-
-
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
Migrate variants with nil unit_value #6792
Migrate variants with nil unit_value #6792
Conversation
is there something preventing us from enforcing that at DB-level? without a DB constraint, we can't guarantee so. |
I don't think so, I added a line to the migration that puts the constraint there. |
Now I noticed we haven't updated the db/schema's timestamp. This needs the be executed locally and the schema updated. I move it to Dev test in case you want to play with it in a staging server @andrewpbrett |
@sauloperez I tested it out; I created a Variant with a |
That's enough IMO. |
I beefed this up a bit, let me know if you still think it’s okay to merge @sauloperez. I did a dev test and will deploy it to a staging server as well. After running it locally I can no longer force a value of NaN into the DB even by setting it directly. |
change_column_null :spree_variants, :unit_value, false, 1 | ||
change_column_null :spree_variants, :weight, false, 0.0 | ||
execute "ALTER TABLE spree_variants ADD CONSTRAINT check_unit_value_for_nan CHECK (unit_value <> 'NaN')" | ||
execute "ALTER TABLE spree_variants ADD CONSTRAINT check_weight_for_nan CHECK (weight <> 'NaN')" |
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.
😍 finally we leverage PostgreSQL features
spree_products: { variant_unit: "items" }, | ||
spree_variants: { unit_value: [nil, Float::NAN] } | ||
).find_each do |variant| | ||
Spree::Variant.where(unit_value: [nil, Float::NAN]).find_each do |variant| |
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.
lol I didn't know NAN
existed
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 know it exists in Rails, but I'm surprised Postgres allows saving it as a value on a decimal field in the DB...
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.
you gotta love the 🐘 ❤️
What? Why?
Addresses #6737
Variants with a
unit_value
ofnil
and whose product usesitems
cannot be changed to useweight
as theirvariant_unit
. We have some assumptions in the code thatunit_value
is nevernil
.What should we test?
The issue described in #6737 will no longer be reproducible
without manually altering the database directlyeven if you try to alter the database directly.Release notes
Changelog Category: User facing changes | Technical changes
Dependencies
Documentation updates