Project

General

Profile

Support #1550

Migration from v 0.1.5 to lastest 0.4 fails

Added by Ky Zh over 10 years ago. Updated almost 10 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

We are running an antic version of Foreman (0.1.5 ?).
I'm now trying to my historical data from it into a newly installed 0.4

So far i exported my data [1] , imported it back [2] on an other box
Then i run the with the instruction [4].

On the "RAILS_ENV=production rake db:migrate" step, the rake job failed [4]
I also included the tables [5] diff existing between 0.1.5 and 0.4.0 (from our testing environment)

I will try to reproduce once again to catch the --trace the first time around

Other relevant informations:
ruby -v ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03

[1] mysqldump -u root -p puppet > /var/satellite/puppetdb.sql
[2] mysql -u root -p puppet < /home/florentin.raud/puppet.sql
[3] http://theforeman.org/projects/foreman/wiki/Upgrade_instructions

[4] RAILS_ENV=production rake db:migrate
WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
at /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
SimplifyParameters: migrating ===========================================
-- remove_index(:parameters, [:host_id, :type])
> 0.0569s
-
remove_index(:parameters, [:hostgroup_id, :type])
> 0.0080s
-
remove_index(:parameters, [:domain_id, :type])
> 0.0026s
-
rename_column(:parameters, :host_id, :reference_id)
> 0.0741s
-
add_index(:parameters, [:reference_id, :type])
-> 0.0028s
rake aborted!
An error has occurred, all later migrations canceled:

undefined method `priority=' for #<GroupParameter:0x1c9cc2e8>

Tasks: TOP => db:migrate
(See full trace by running task with --trace)
  1. Yet another run
    [foreman@host /opt/foreman]$ RAILS_ENV=production rake db:migrate --trace
    WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
    at /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
    • Invoke db:migrate (first_time)
    • Invoke environment (first_time)
    • Execute environment
    • Execute db:migrate
      SimplifyParameters: migrating ===========================================
      -- remove_index(:parameters, [:host_id, :type])
      > 0.0004s
      -
      remove_index(:parameters, [:hostgroup_id, :type])
      > 0.0002s
      -
      remove_index(:parameters, [:domain_id, :type])
      > 0.0002s
      -
      rename_column(:parameters, :host_id, :reference_id)
      rake aborted!
      An error has occurred, all later migrations canceled:

No such column: parameters.host_id
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:530:in `rename_column'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `method_missing'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:348:in `method_missing'
./db/migrate//20100525094200_simplify_parameters.rb:7:in `up_without_benchmarks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `__send__'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:491:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `call'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `ddl_transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:490:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `each'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:401:in `up'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:383:in `migrate'
/opt/foreman/vendor/rails/railties/lib/tasks/databases.rake:112
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/opt/ruby-enterprise-1.8.7/bin/rake:19:in `load'
/opt/ruby-enterprise-1.8.7/bin/rake:19
Tasks: TOP => db:migrate

[5] mysqldump --no-data --tables --create-options -u root --databases puppet

Associated revisions

Revision 0b6d53d6 (diff)
Added by Unknown almost 10 years ago

fixes #1550 : Test existance before removing index and column.

In case where reference_id exist, but domain_id, hostgroup_id, domain_id don't, migration should'nt fail

History

#1 Updated by Ky Zh over 10 years ago

I deleted the DB, re-imported my old DB and did "RAILS_ENV=production rake db:migrate --trace".
WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
at /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
  • Invoke db:migrate (first_time)
  • Invoke environment (first_time)
  • Execute environment
  • Execute db:migrate
    SimplifyParameters: migrating ===========================================
    -- remove_index(:parameters, [:host_id, :type])
    > 0.0286s
    -
    remove_index(:parameters, [:hostgroup_id, :type])
    > 0.0032s
    -
    remove_index(:parameters, [:domain_id, :type])
    > 0.0031s
    -
    rename_column(:parameters, :host_id, :reference_id)
    > 0.0726s
    -
    add_index(:parameters, [:reference_id, :type])
    -> 0.0185s
    rake aborted!
    An error has occurred, all later migrations canceled:

undefined method `priority=' for #<GroupParameter:0xb203bd0>
/opt/foreman/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:255:in `method_missing'
/opt/foreman/app/models/parameter.rb:16:in `after_initialize'
/opt/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:347:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:347:in `callback'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1691:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1691:in `instantiate_without_polymorphic_checks'
/opt/foreman/vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/base.rb:52:in `instantiate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:665:in `find_by_sql'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:665:in `collect!'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:665:in `find_by_sql'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:1582:in `find_every'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:619:in `find'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:639:in `all'
./db/migrate//20100525094200_simplify_parameters.rb:13:in `up_without_benchmarks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `__send__'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:491:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `call'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `ddl_transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:490:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `each'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:401:in `up'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:383:in `migrate'
/opt/foreman/vendor/rails/railties/lib/tasks/databases.rake:112
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/opt/ruby-enterprise-1.8.7/bin/rake:19:in `load'
/opt/ruby-enterprise-1.8.7/bin/rake:19
Tasks: TOP => db:migrate

#2 Updated by Ohad Levy over 10 years ago

if you rename db/migrate/20110327123639_add_priority_to_parameter.rb to be a lower number then db/migrate/20100525094200_simplify_parameters.rb, does it work?

#3 Updated by Ky Zh over 10 years ago

[foreman@host /opt/foreman/db/migrate]$ mv {20110327123639,20100525094100}_add_priority_to_parameter.rb
WARNING: 'require 'rake/rdoctask'' is deprecated. Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
at /opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
  • Invoke db:migrate (first_time)
  • Invoke environment (first_time)
  • Execute environment
  • Execute db:migrate
    AddPriorityToParameter: migrating =======================================
    -- add_column(:parameters, :priority, :integer)
    -> 0.0064s
    AddPriorityToParameter: migrated (0.1078s) ==============================
SimplifyParameters: migrating ===========================================
-- remove_index(:parameters, [:host_id, :type])
> 0.0037s
-
remove_index(:parameters, [:hostgroup_id, :type])
> 0.0033s
-
remove_index(:parameters, [:domain_id, :type])
> 0.0025s
-
rename_column(:parameters, :host_id, :reference_id)
> 0.0038s
-
add_index(:parameters, [:reference_id, :type])
-> 0.0028s
rake aborted!
An error has occurred, all later migrations canceled:

unknown attribute: comment
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2918:in `assign_attributes'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2914:in `each'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2914:in `assign_attributes'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2787:in `attributes='
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2477:in `initialize'
/opt/foreman/vendor/rails/activerecord/lib/active_record/reflection.rb:162:in `new'
/opt/foreman/vendor/rails/activerecord/lib/active_record/reflection.rb:162:in `build_association'
/opt/foreman/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:467:in `create_record'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2182:in `with_scope'
/opt/foreman/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:466:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:466:in `create_record'
/opt/foreman/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:246:in `create'
/opt/foreman/vendor/plugins/acts_as_audited/lib/acts_as_audited.rb:252:in `write_audit'
/opt/foreman/vendor/plugins/acts_as_audited/lib/acts_as_audited.rb:241:in `audit_update'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in `call'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
/opt/foreman/vendor/rails/activesupport/lib/active_support/callbacks.rb:276:in `run_callbacks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:344:in `callback'
/opt/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:281:in `update'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2927:in `create_or_update_without_callbacks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/callbacks.rb:250:in `create_or_update'
/opt/foreman/vendor/rails/activerecord/lib/active_record/base.rb:2577:in `save_without_validation'
/opt/foreman/vendor/rails/activerecord/lib/active_record/validations.rb:1090:in `save_without_dirty'
/opt/foreman/vendor/rails/activerecord/lib/active_record/dirty.rb:79:in `save_without_transactions'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in `transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:196:in `save'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/opt/foreman/vendor/rails/activerecord/lib/active_record/transactions.rb:196:in `save'
./db/migrate//20100525094200_simplify_parameters.rb:23:in `up_without_benchmarks'
./db/migrate//20100525094200_simplify_parameters.rb:13:in `each'
./db/migrate//20100525094200_simplify_parameters.rb:13:in `up_without_benchmarks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `__send__'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:491:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `call'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `ddl_transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:490:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `each'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:401:in `up'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:383:in `migrate'
/opt/foreman/vendor/rails/railties/lib/tasks/databases.rake:112
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/opt/ruby-enterprise-1.8.7/bin/rake:19:in `load'
/opt/ruby-enterprise-1.8.7/bin/rake:19
Tasks: TOP => db:migrate

#4 Updated by Ky Zh over 10 years ago

So i did th equivalent of "20100525094200_simplify_parameters.rb" by hand.

Do the migration up to 20100524080302

RAILS_ENV=production  rake db:migrate:up VERSION=20100524080302 --trace

Then logged into mysql

myslq -u root -p 

Once in mysql, choose the puppet db

use puppet; 

I now pretty much translate teh migration into msql
Drop the indexes:

ALTER TABLE parameters DROP INDEX index_parameters_on_host_id_and_type;
ALTER TABLE parameters DROP INDEX index_parameters_on_domain_id_and_type;
ALTER TABLE parameters DROP INDEX index_parameters_on_hostgroup_id_and_type;

rename the column

alter table parameters change host_id reference_id int(11);

Re-create an index

CREATE INDEX index_parameters_on_reference_id_and_type ON parameters(reference_id,type);

Then print the table content

select * from parameters ;

Ensure your table looks like that:

reference_id = null,  hostgroup_id  = null, domain_id  = null, type = CommonParameter
reference_id = null,  hostgroup_id  = null, domain_id  =    X, type = DomainParameter
reference_id = null,  hostgroup_id  = X   , domain_id  = null, type = GroupParameter
reference_id = X   ,  hostgroup_id  =null , domain_id  = null, type = HostParameter

I update reference_id with either the domain or the hostgroup ID

update parameters set reference_id=domain_id where domain_id IS NOT NULL;
update parameters set reference_id=hostgroup_id where hostgroup_id IS NOT NULL;

Delete the table, now made redundant

alter table parameters drop hostgroup_id;
alter table parameters drop domain_id;

That allow me to go as far as "VERSION=20101019183859" (with 362731, it is taking some time).

If i try to run the next one in line "20101019122857_add_metrics_to_report.rb", it borkes.


==  AddMetricsToReport: migrating =============================================
-- add_column(:reports, :metrics, :text)
rake aborted!
An error has occurred, all later migrations canceled:

Mysql::Error: The table '#sql-58c_24' is full: ALTER TABLE `reports` ADD `metrics` text
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:324:in `execute'
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:489:in `add_column'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `method_missing'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:348:in `method_missing'
./db/migrate//20101019122857_add_metrics_to_report.rb:3:in `up_without_benchmarks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `__send__'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:491:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `call'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `ddl_transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:490:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `each'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:401:in `up'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:383:in `migrate'
/opt/foreman/vendor/rails/railties/lib/tasks/databases.rake:112
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/opt/ruby-enterprise-1.8.7/bin/rake:19:in `load'
/opt/ruby-enterprise-1.8.7/bin/rake:19
Tasks: TOP => db:migrate

#5 Updated by Ohad Levy over 10 years ago

awesome!

hmm.. it says table is full
I wonder if it might be best to expire old reports first.

then I think the rest of the migrations should work?

#6 Updated by Ky Zh over 10 years ago

Started from scratch, without the table report.

mysqldump  -u root -p --ignore-table=puppet.reports puppet > /tmp/export.sql

Imported the data back in.

mysql -u root -p puppet < /tmp/export.sql

Recreated the table:

DROP TABLE IF EXISTS `reports`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `reports` (
  `id` int(11) NOT NULL auto_increment,
  `host_id` int(11) NOT NULL,
  `log` mediumtext,
  `reported_at` datetime default NULL,
  `created_at` datetime default NULL,
  `updated_at` datetime default NULL,
  `status` int(11) default NULL,
  PRIMARY KEY  (`id`),
  KEY `index_reports_on_reported_at_and_host_id` (`reported_at`,`host_id`),
  KEY `index_reports_on_status` (`status`),
  KEY `index_reports_on_host_id` (`host_id`),
  KEY `index_reports_on_reported_at` (`reported_at`)
) ENGINE=InnoDB AUTO_INCREMENT=410903 DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

I then carry on with what i did in http://theforeman.org/issues/1550#note-4 again.

That help me to go a bit forward

RAILS_ENV=production  rake db:migrate:up VERSION=20110216101848 --trace

But still, it failed at 20110301154453_add_managed_to_hosts.rb

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
==  AddManagedToHosts: migrating ==============================================
-- add_column(:hosts, :managed, :boolean)
rake aborted!
An error has occurred, all later migrations canceled:

Mysql::Error: Duplicate column name 'managed': ALTER TABLE `hosts` ADD `managed` tinyint(1)
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:324:in `execute'
/opt/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:489:in `add_column'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:352:in `method_missing'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:328:in `say_with_time'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:348:in `method_missing'
./db/migrate//20110301154453_add_managed_to_hosts.rb:3:in `up_without_benchmarks'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `send'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/benchmark.rb:293:in `measure'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `__send__'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:365:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:491:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `call'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:567:in `ddl_transaction'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:490:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `each'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:477:in `migrate'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:401:in `up'
/opt/foreman/vendor/rails/activerecord/lib/active_record/migration.rb:383:in `migrate'
/opt/foreman/vendor/rails/railties/lib/tasks/databases.rake:112
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/opt/ruby-enterprise-1.8.7/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/opt/ruby-enterprise-1.8.7/bin/rake:19:in `load'
/opt/ruby-enterprise-1.8.7/bin/rake:19
Tasks: TOP => db:migrate

I understand that it complain about managed that already exists.
By looking inside the table , its always set to NULL.

Now i'm sure what i should update "managed" with.
I assume "true", unless one the bellow column end up NULL or not empty

host.update_attribute :managed, !!host.operatingsystem_id and !!host.architecture_id and (!!host.ptable_id or not host.disk.empty?)

So one should see the managed row to update with

select id from hosts where (architecture_id is NULL and operatingsystem_id is NULL and (ptable_id is NULL or disk is NULL));

Would the above assumption correct ?

#7 Updated by David M. over 10 years ago

I also have seen this kind of issue on a test-install yesterday.

Testsetup:

puppet+puppetmaster and foreman are on the same host (RHEL6.2 x86_64).

As soon as puppet creates the required tables in mysql, the migration script fails.
If the database is empty, migration works.

It got stuck on the same script as mention above.

#8 Updated by Ky Zh over 10 years ago

I realise that "managed" was the button on the corner right when you edit a host.
As it will start with a non managed state (NULL in the database), I don't actually need to worry about it.

To get it to work, remove the migration

rm db/migrate/20110301154453_add_managed_to_hosts.rb

It then finnished nicely.

#9 Updated by Ohad Levy over 10 years ago

  • Status changed from New to Resolved

#10 Updated by Ohad Levy almost 10 years ago

  • Target version set to 1.1

Also available in: Atom PDF