Bug #17666

Upgrade fails during db:migration

Added by Mike McCune 10 months ago. Updated 10 months ago.

Status:Closed
Priority:Normal
Assigned To:Tomer Brisker
Category:DB migrations
Target version:-
Difficulty: Bugzilla link:1404436
Found in release:1.13.0 Pull request:https://github.com/theforeman/foreman/pull/4109
Story points-
Velocity based estimate-
Release1.13.3Release relationshipAuto

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1404436

1) Upgrade from Satellite 6.2.4 to 6.2.5 and receive this error:

  • Execute db:load_config
  • Execute db:migrate
    20151104100257 AddHostsCountToHostgroup: migrating =======================
    -- add_column(:hostgroups, :hosts_count, :integer, {:default=>0})
    -> 0.0454s
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:

undefined method `counter_cache_column' for nil:NilClass/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/counter_cache.rb:33:in `block in reset_counters'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/counter_cache.rb:22:in `each'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/counter_cache.rb:22:in `reset_counters'
/usr/share/foreman/db/migrate/20151104100257_add_hosts_count_to_hostgroup.rb:5:in `block in up'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/delegation.rb:46:in `each'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/relation/delegation.rb:46:in `each'
/usr/share/foreman/db/migrate/20151104100257_add_hosts_count_to_hostgroup.rb:4:in `up'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:598:in `exec_migration'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/opt/rh/rh-ruby22/root/usr/share/ruby/benchmark.rb:288:in `measure'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:578:in `block in migrate'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:577:in `migrate'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:752:in `migrate'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/transactions.rb:208:in `transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:1038:in `ddl_transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:953:in `block in migrate'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:949:in `each'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:949:in `migrate'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:807:in `up'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/migration.rb:785:in `migrate'
/opt/rh/rh-ror41/root/usr/share/gems/gems/activerecord-4.1.5/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/opt/rh/rh-ruby22/root/usr/share/ruby/monitor.rb:211:in `mon_synchronize'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/opt/rh/rh-ruby22/root/usr/share/gems/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/opt/rh/rh-ruby22/root/usr/bin/rake:33:in `<main>'


Related issues

Related to Foreman - Bug #12193: Deadlock occuring when creating host Closed 10/16/2015
Related to Foreman - Feature #11307: Show number of hosts in Host Group overview Closed 08/06/2015

Associated revisions

Revision 1f6cc22b
Added by Tomer Brisker 10 months ago

Fixes #17666 - prevent migration failures on counter cache

Removal of counter cache causes migrations relying on the
`reset_counters` method to fail. The migrations are changed to not
update the counters (which are now removed anyways).

Revision 678e2339
Added by Tomer Brisker 10 months ago

Fixes #17666 - prevent migration failures on counter cache

Removal of counter cache causes migrations relying on the
`reset_counters` method to fail. The migrations are changed to not
update the counters (which are now removed anyways).

(cherry picked from commit 1f6cc22ba15af8ed0d85cc882cb6878c282e2dd2)

Revision 7b83ce6b
Added by Tomer Brisker 10 months ago

Fixes #17666 - prevent migration failures on counter cache

Removal of counter cache causes migrations relying on the
`reset_counters` method to fail. The migrations are changed to not
update the counters (which are now removed anyways).

(cherry picked from commit 1f6cc22ba15af8ed0d85cc882cb6878c282e2dd2)

History

#1 Updated by The Foreman Bot 10 months ago

  • Status changed from New to Ready For Testing
  • Assigned To set to Tomer Brisker
  • Pull request https://github.com/theforeman/foreman/pull/4109 added

#2 Updated by Lukas Zapletal 10 months ago

  • Subject changed from Satellite 6.2.5 upgrade fails during db:migration to Satellite 6.2.5 upgrade fails during db:migration
  • Release set to 1.14.0

This is worth backporting into 1.13 or 1.14. I am setting 1.14 for now.

#3 Updated by Dominic Cleal 10 months ago

  • Release deleted (1.14.0)

1.14.0 was branched two weeks ago, and it's unclear to me that this is a regression in 1.14.0 vs 1.13.2. The description is useless, what do these versions correspond to? Please use Foreman version numbers when filing in Foreman's bug tracker.

#4 Updated by Anonymous 10 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#5 Updated by Tomer Brisker 10 months ago

  • Related to Bug #12193: Deadlock occuring when creating host added

#6 Updated by Tomer Brisker 10 months ago

  • Related to Feature #11307: Show number of hosts in Host Group overview added

#7 Updated by Tomer Brisker 10 months ago

  • Subject changed from Satellite 6.2.5 upgrade fails during db:migration to Upgrade fails during db:migration
  • Found in release set to 1.13.0

Counter caches were removed in 1.13. The last migration using the `reset_counter` method was introduced in 1.11.
Any user attempting to upgrade directly from 1.10 or older to 1.13 or newer will hit this issue.

#8 Updated by Dominic Cleal 10 months ago

  • Release set to 1.13.3
  • Found in release deleted (1.13.0)

Thanks, this should be on 1.13.x then. (Not that these upgrades are supported, they were even removed from the test matrix.)

#9 Updated by Dominic Cleal 10 months ago

  • Found in release set to 1.13.0

Also available in: Atom PDF