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

Update adjustments #7121

Merged
merged 2 commits into from
Mar 19, 2021
Merged

Conversation

Matt-Yorkley
Copy link
Contributor

@Matt-Yorkley Matt-Yorkley commented Mar 15, 2021

What? Why?

Closes #7120

Data migration to ensure any adjustments created without an order are re-associated with their order.

Included schema changes from running db:migrate in a separate commit; the formatting in schema.rb has changed a bit in Rails 5, so I wanted to keep the diffs separate.

What should we test?

If we deploy to a staging server that has a couple of faulty adjustments, they should be fixed afterwards.

  • uk-staging has outdated adjustments.
  • au-staging doesn't.

Release notes

Data migration to fix any adjustments missing an order id

Changelog Category: Technical changes

@Matt-Yorkley Matt-Yorkley self-assigned this Mar 15, 2021
Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

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

neat 👌

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

That should do the trick.

@mkllnk mkllnk added the pr-staged-uk staging.openfoodnetwork.org.uk label Mar 18, 2021
@mkllnk
Copy link
Member

mkllnk commented Mar 18, 2021

💣 Deployment failed:

TASK [deploy : migrate database] ***********************************************
fatal: [staging.openfoodnetwork.org.uk]: FAILED! => {"changed": true, "cmd": ["bash", "-lc", "bundle exec rake db:migrate RAILS_ENV=staging"], "delta": "0:00:07.371338", "end": "2021-03-18 03:31:04.906679", "msg": "non-zero return code", "rc": 1, "start": "2021-03-18 03:30:57.535341", "stderr": "Association Tracking for PaperTrail has been extracted to a separate gem. To use it, please add `paper_trail-association_tracking` to your Gemfile. If you don't use it (most people don't, that's the default) and you set `track_associations = false` somewhere (probably a rails initializer) you can remove that line now.\nrake aborted!\nStandardError: An error has occurred, this and all later migrations canceled:\n\nPG::UndefinedColumn: ERROR:  column \"spree_adjustments\" of relation \"spree_adjustments\" does not exist\nLINE 1: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = ...\n                                       ^\n: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = spree_adjustments.adjustable_id WHERE \"spree_adjustments\".\"order_id\" IS NULL AND \"spree_adjustments\".\"adjustable_type\" = $1\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `block in exec_no_cache'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activesupport-5.0.7.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `exec_no_cache'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:589:in `execute_and_clear'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/relation.rb:395:in `update_all'\n/home/openfoodnetwork/apps/openfoodnetwork/releases-old/2021-03-18-033022/db/migrate/20210315163900_update_associations.rb:11:in `up'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:792:in `exec_migration'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:772:in `block in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:771:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:951:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `block in ddl_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/transactions.rb:211:in `transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `ddl_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `each'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `migrate_without_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `block in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1319:in `with_advisory_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1006:in `up'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:984:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:163:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/rake.rb:20:in `execute'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'\n/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `load'\n/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `<main>'\n\nCaused by:\nActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column \"spree_adjustments\" of relation \"spree_adjustments\" does not exist\nLINE 1: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = ...\n                                       ^\n: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = spree_adjustments.adjustable_id WHERE \"spree_adjustments\".\"order_id\" IS NULL AND \"spree_adjustments\".\"adjustable_type\" = $1\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `block in exec_no_cache'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activesupport-5.0.7.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `exec_no_cache'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:589:in `execute_and_clear'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/relation.rb:395:in `update_all'\n/home/openfoodnetwork/apps/openfoodnetwork/releases-old/2021-03-18-033022/db/migrate/20210315163900_update_associations.rb:11:in `up'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:792:in `exec_migration'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:772:in `block in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:771:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:951:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `block in ddl_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/transactions.rb:211:in `transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `ddl_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `each'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `migrate_without_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `block in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1319:in `with_advisory_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1006:in `up'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:984:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:163:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/rake.rb:20:in `execute'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'\n/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `load'\n/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `<main>'\n\nCaused by:\nPG::UndefinedColumn: ERROR:  column \"spree_adjustments\" of relation \"spree_adjustments\" does not exist\nLINE 1: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = ...\n                                       ^\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `block in exec_no_cache'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activesupport-5.0.7.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `exec_no_cache'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:589:in `execute_and_clear'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/relation.rb:395:in `update_all'\n/home/openfoodnetwork/apps/openfoodnetwork/releases-old/2021-03-18-033022/db/migrate/20210315163900_update_associations.rb:11:in `up'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:792:in `exec_migration'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:772:in `block in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:771:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:951:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `block in ddl_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/transactions.rb:211:in `transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `ddl_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `each'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `migrate_without_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `block in migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1319:in `with_advisory_lock'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1006:in `up'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:984:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:163:in `migrate'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/rake.rb:20:in `execute'\n/home/openfoodnetwork/.gem/ruby/2.4.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'\n/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `load'\n/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `<main>'\nTasks: TOP => db:migrate\n(See full trace by running task with --trace)", "stderr_lines": ["Association Tracking for PaperTrail has been extracted to a separate gem. To use it, please add `paper_trail-association_tracking` to your Gemfile. If you don't use it (most people don't, that's the default) and you set `track_associations = false` somewhere (probably a rails initializer) you can remove that line now.", "rake aborted!", "StandardError: An error has occurred, this and all later migrations canceled:", "", "PG::UndefinedColumn: ERROR:  column \"spree_adjustments\" of relation \"spree_adjustments\" does not exist", "LINE 1: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = ...", "                                       ^", ": UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = spree_adjustments.adjustable_id WHERE \"spree_adjustments\".\"order_id\" IS NULL AND \"spree_adjustments\".\"adjustable_type\" = $1", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `block in exec_no_cache'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activesupport-5.0.7.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `exec_no_cache'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:589:in `execute_and_clear'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/relation.rb:395:in `update_all'", "/home/openfoodnetwork/apps/openfoodnetwork/releases-old/2021-03-18-033022/db/migrate/20210315163900_update_associations.rb:11:in `up'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:792:in `exec_migration'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:772:in `block in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:771:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:951:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `block in ddl_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/transactions.rb:211:in `transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `ddl_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `each'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `migrate_without_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `block in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1319:in `with_advisory_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1006:in `up'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:984:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:163:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/rake.rb:20:in `execute'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'", "/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `load'", "/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `<main>'", "", "Caused by:", "ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column \"spree_adjustments\" of relation \"spree_adjustments\" does not exist", "LINE 1: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = ...", "                                       ^", ": UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = spree_adjustments.adjustable_id WHERE \"spree_adjustments\".\"order_id\" IS NULL AND \"spree_adjustments\".\"adjustable_type\" = $1", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `block in exec_no_cache'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activesupport-5.0.7.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `exec_no_cache'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:589:in `execute_and_clear'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/relation.rb:395:in `update_all'", "/home/openfoodnetwork/apps/openfoodnetwork/releases-old/2021-03-18-033022/db/migrate/20210315163900_update_associations.rb:11:in `up'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:792:in `exec_migration'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:772:in `block in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:771:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:951:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `block in ddl_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/transactions.rb:211:in `transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `ddl_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `each'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `migrate_without_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `block in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1319:in `with_advisory_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1006:in `up'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:984:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:163:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/rake.rb:20:in `execute'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'", "/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `load'", "/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `<main>'", "", "Caused by:", "PG::UndefinedColumn: ERROR:  column \"spree_adjustments\" of relation \"spree_adjustments\" does not exist", "LINE 1: UPDATE \"spree_adjustments\" SET spree_adjustments.order_id = ...", "                                       ^", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `async_exec'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `block in exec_no_cache'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:590:in `block in log'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activesupport-5.0.7.2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract_adapter.rb:583:in `log'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:600:in `exec_no_cache'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:589:in `execute_and_clear'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:116:in `exec_delete'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:133:in `update'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/query_cache.rb:17:in `update'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/relation.rb:395:in `update_all'", "/home/openfoodnetwork/apps/openfoodnetwork/releases-old/2021-03-18-033022/db/migrate/20210315163900_update_associations.rb:11:in `up'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:792:in `exec_migration'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:773:in `block (2 levels) in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:772:in `block in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:771:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:951:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1232:in `block in execute_migration_in_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `block in ddl_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/transactions.rb:211:in `transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1300:in `ddl_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1231:in `execute_migration_in_transaction'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1203:in `block in migrate_without_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `each'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1202:in `migrate_without_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `block in migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1319:in `with_advisory_lock'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1150:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:1006:in `up'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/migration.rb:984:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:163:in `migrate'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/rake.rb:20:in `execute'", "/home/openfoodnetwork/.gem/ruby/2.4.0/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'", "/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `load'", "/home/openfoodnetwork/.rbenv/versions/2.4.4/bin/bundle:23:in `<main>'", "Tasks: TOP => db:migrate", "(See full trace by running task with --trace)"], "stdout": "== 20210315163900 UpdateAssociations: migrating ===============================", "stdout_lines": ["== 20210315163900 UpdateAssociations: migrating ==============================="]}
Thursday 18 March 2021  03:31:04 +0000 (0:00:07.506)       0:00:42.513 ******** 

We must not repeat the table name.

@mkllnk mkllnk removed the pr-staged-uk staging.openfoodnetwork.org.uk label Mar 18, 2021
@Matt-Yorkley
Copy link
Contributor Author

Updated 👍 I gave it a quick try locally, and the migration ran successfully.

@mkllnk mkllnk added the pr-staged-uk staging.openfoodnetwork.org.uk label Mar 19, 2021
@mkllnk
Copy link
Member

mkllnk commented Mar 19, 2021

I deployed to UK staging. Deploy was successful and afterwards there were not outdated adjustments:

Spree::Adjustment.where(order_id: nil, adjustable_type: "Spree::Order").count
=> 0

Spree::Adjustment.where(order_id: nil).count
=> 0

@mkllnk
Copy link
Member

mkllnk commented Mar 19, 2021

I also tested the UK production database locally.

# select count(*) from spree_adjustments where order_id is null;
 count 
-------
    52
$ ./bin/rake db:migrate
...
== 20210315163900 UpdateAssociations: migrating ===============================
== 20210315163900 UpdateAssociations: migrated (0.0273s) ======================
# select count(*) from spree_adjustments where order_id is null;
 count 
-------
     0

Perfect!

@mkllnk mkllnk merged commit 16d629e into openfoodfoundation:master Mar 19, 2021
@filipefurtad0 filipefurtad0 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

follow-up on PR#7112: data migration to deal with "ghost" adjustments
4 participants