-
-
Notifications
You must be signed in to change notification settings - Fork 724
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
Fix RedundantPresenceValidationOnBelongs on some files (part II) #12414
Fix RedundantPresenceValidationOnBelongs on some files (part II) #12414
Conversation
- presence: true is redundant since Rails 5.0 BUT applies with new default config of belongs_to_required_by_default to true. Lots of files with belongs_to_required_by_default = false (backward compatibility). So: deleting this setting implies to adding optional: true - added 'NOT NULL' constraints so model constraints match with contraints on DB tables. - corresponding migration files to match AR Models & DB tables - rake tasks to check corrupt data (ie: NULL/nil in id fields) - updated the todo
app/models/spree/product_property.rb
Outdated
self.belongs_to_required_by_default = false | ||
|
||
belongs_to :product, class_name: "Spree::Product", touch: true | ||
belongs_to :product, class_name: "Spree::Product", touch: true, optional: true |
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.
It don't think it makes sense to have the product optional here.
I checked the production server and none of them have a product property with a product_id
set to null so it's safe to the change. @openfoodfoundation/core-devs what do you think ?
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.
Well if there are no null product_id
, I guess I could also update the migration file.
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.
Indeed, ProductProperty is a join table between Product and Property, so the association is definitely required.
So both the product_id and property_id columns can become NOT NULL
. I'm not sure if Gaetan checked all prod servers yet, so we might need to check that before deploying.
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 just did, and we are good, not funny data :)
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.
Cool. So I have made the update.
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. We would like to make spree_product_properties.product_id
required as well.
app/models/spree/product_property.rb
Outdated
self.belongs_to_required_by_default = false | ||
|
||
belongs_to :product, class_name: "Spree::Product", touch: true | ||
belongs_to :product, class_name: "Spree::Product", touch: true, optional: true |
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.
Indeed, ProductProperty is a join table between Product and Property, so the association is definitely required.
So both the product_id and property_id columns can become NOT NULL
. I'm not sure if Gaetan checked all prod servers yet, so we might need to check that before deploying.
- product id required - DB + AR model
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, thank you!
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.
Nice, thank you
Migration succeeded on au_staging:
@rioug just double-checking, can you confirm we are good to merge? |
We are all good, merging. |
What? Why?
What should we test?
After migration, all tests should pass and no rubocop offense should be raised.
Run the 3 rake files, to check it any corrupt data is present.
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates