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 two files #12493

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 rake file, to check it any corrupt data is present.

Note: only 1 migration file here because the null were already enforced at DB level for the variant_overrides table.

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

@cyrillefr
Copy link
Contributor Author

cyrillefr commented May 17, 2024

Hello @sigmundpetersen , @dacook

I would like a rerun of the checks due to some strange error that do not occur locally.
Thanks :)

@sigmundpetersen
Copy link
Contributor

I have re-run the spec a couple of times @cyrillefr but it seems consistent on CI

@sigmundpetersen
Copy link
Contributor

Seems there's a fix in #12490, you could wait for that

@sigmundpetersen
Copy link
Contributor

Hi @cyrillefr , you can rebase this now to get the fixes from #12490

    - 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
@cyrillefr cyrillefr force-pushed the RedundantPresenceValidationOnBelongs_part_IV branch from 3317b1f to 46cd60a Compare May 22, 2024 07:44
@cyrillefr
Copy link
Contributor Author

Hello @sigmundpetersen ,

Thank you.

@@ -0,0 +1,5 @@
class RequireTaxCategoryOnTaxRate < ActiveRecord::Migration[7.0]
def change
change_column_null :spree_tax_rates, :tax_category_id, false
Copy link
Member

Choose a reason for hiding this comment

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

I double-checked the assumption on all prod servers:

sql='select count(*) from spree_tax_rates where tax_category_id is null;'
ansible all_prod -u openfoodnetwork -a "psql -h localhost openfoodnetwork ofn_user -c '$sql'"

All clear! ✔️

Comment on lines 5 to 16
desc 'Checking missing required ids in Spree::TaxRate'
task check_missing_required_missing_ids_in_spree_tax_rates: :environment do
puts 'Checking for null tax_category_id'
ids = Spree::TaxRate.where(tax_category_id: nil).pluck(:id)

if ids.empty?
puts 'No NULL tax_category_id found in spree_tax_rates'
else
puts 'NULL tax_category_ids s have been found in spree_tax_rates:'
print ids
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Thank your for providing this. But having it in this commit doesn't really help. The rake task can only be run once the code has been deployed. But if you deploy this commit then the migration is run already.

I did a pre-flight check querying all servers via Ansible. Only admins can do that, of course. I'm not sure if there's any better approach.

Can you remove this file again? Or maybe I quickly do it to save time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @mkllnk , I will make these scripts in a separate commits ahead of migrations for next time.
Also, I will make a PR to delete these one-short rake taskes I have created.

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.

👌 Perfect

@dacook
Copy link
Member

dacook commented May 22, 2024

Fixed conflict with GitHub UI.
Apparently that does a merge, will consider a manual rebase next time..

@dacook dacook added pr-staged-au staging.openfoodnetwork.org.au pr-staged-fr staging.coopcircuits.fr and removed pr-staged-au staging.openfoodnetwork.org.au pr-staged-fr staging.coopcircuits.fr labels May 22, 2024
@dacook dacook merged commit e30dc1b into openfoodfoundation:master May 23, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants