Skip to content
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

Conversation

cyrillefr
Copy link
Contributor

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):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

- 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
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
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Collaborator

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 :)

Copy link
Contributor Author

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.

@rioug rioug added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Apr 29, 2024
Copy link
Member

@dacook dacook left a 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.

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
Copy link
Member

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.

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

@dacook dacook added the pr-staged-au staging.openfoodnetwork.org.au label Apr 30, 2024
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you

@dacook dacook removed the pr-staged-au staging.openfoodnetwork.org.au label Apr 30, 2024
@dacook
Copy link
Member

dacook commented Apr 30, 2024

Migration succeeded on au_staging:

deploy : migrate database ---------------------------------------------- 10.56s

@rioug just double-checking, can you confirm we are good to merge?

@rioug
Copy link
Collaborator

rioug commented May 1, 2024

We are all good, merging.

@rioug rioug merged commit 04f77b5 into openfoodfoundation:master May 1, 2024
52 checks passed
@cyrillefr cyrillefr deleted the RedundantPresenceValidationOnBelongs_part_II branch June 11, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants