-
-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up unused calculator currency data #10333
base: master
Are you sure you want to change the base?
Clean up unused calculator currency data #10333
Conversation
Hey @dacook , Signalling some conflicts in this PR - could you address them please? Thanks! |
4a5e341
to
51934c5
Compare
Thanks Filipe, done. |
This depends on openfoodfoundation#10318 being deployed first.
DB query / Dev testI thought it worth demonstrating how I tested the query. 1. List all calculator preferences
2. Limit query to currency only
3. After running migration on dev
All other preferences still exist:
|
51934c5
to
0f41ee2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! (and what a nice how to test section! 👏 )
As it delete data, I'd invoke a second review on that one!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Such a simple pull request and I still find things to talk about. 😉
I was just about to approve this and then I was wondering if the code is still storing the default currency here. How do we test that this is safe? Do we add a database condition on the key name and see if the specs blow up? That would only be a temporary test. Tricky. 🤷
And I found a file which looks like it's still using this value: engines/order_management/app/services/order_management/stock/estimator.rb
Could you have another look?
rows = SpreePreference.where("key like '/calculator%/currency/%'").delete_all | ||
puts "#{rows} rows deleted." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query is so simple and so minimal on Rails use that I would have execute
d plain SQL. But this is good, too. I think it's just a recent preference of mine after years of trying to railsify everything I'm now trying to reduce everything to the bare minimum. And I think that execute
would have given you the output of rows deleted out of the box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, using ActiveRecord doesn't give any advantage here, although perhaps helps avoid errors in writing SQL directly.
I can see that's what Ana did recently too.
def down | ||
# Sorry, the data was deleted! | ||
raise ActiveRecord::IrreversibleMigration | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I often wonder what's best practice here. I tend to not raise an error. So if I want to repeat it, I can rollback and migrate without problem. Or maybe you want to roll back to an older migration and don't need this.
It doesn't really matter, I'm bike-shedding here, but I think that when the rollback doesn't do any harm either then we don't need to raise. If you did raise though then you can pass a message to the error instead of writing a comment. Or do a puts to explain why we can't reverse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point too. Because I'm here now, I'll update it.
🤭 Oh my, good find! Removing code is undo-able, so we should test and deploy that change before deleting data. I'll create a new PR. I should have known this cleanup would blow out.. I've also searched the codebase more thoroughly now, and cannot find any other remaining references to a calculator preference called 'currency'. |
What? Why?
This deletes currency data that was hidden in #10318
Dev test
Run the migration and query the db to check results (see below comment)
What should we test?
This deletes values from the database directly, filtering for "calculator" and "currency".
Check that other preferences are still present, particularly for calculators (eg the saved enterprise fee 'amount' still shows after deployment)
Release notes
Changelog Category: Technical changes
Dependencies