Upgrade from 1.4 to 1.5 : db:migrate fails

Hello,

I recently upgraded a puppet/foreman host from foreman 1.1 to 1.4.
This worked with minor issues (see my previous posts). On the same
machine, I tried to upgrade from 1.4 to the newly released 1.5 and
I have db:migrate failures (see below).

BTW, what is the difference between :

a) root>sudo -u foreman '/usr/share/foreman/extras/dbmigrate
b) root>foreman-rake db:migrate

?

Thank you.

JM

[root@nanx31 ~]# sudo -u foreman '/usr/share/foreman/extras/dbmigrate'
== CalculateCacheForUserRole: migrating

··· ====================================== rake aborted! An error has occurred, all later migrations canceled:

Validation failed: Owner has this role already

Tasks: TOP => db:migrate
(See full trace by running task with --trace)
[root@nanx31 ~]# foreman-rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== CalculateCacheForUserRole: migrating

rake aborted!
An error has occurred, all later migrations canceled:

Validation failed: Owner has this role already
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/validations.rb:56:in
save!' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/attribute_methods/dirty.rb:33:insave!’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in
block in save!' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:295:inblock in with_transaction_returning_status’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in
transaction' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:208:intransaction’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:293:in
with_transaction_returning_status' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:insave!’
/usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb:4:in
block in up' /usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb:3:ineach’
/usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb:3:in
up' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:410:inblock (2 levels) in migrate’
/opt/rh/ruby193/root/usr/share/ruby/benchmark.rb:280:in measure' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:410:inblock in migrate’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:123:in
with_connection' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:389:inmigrate’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:528:in
migrate' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:720:inblock (2 levels) in migrate’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in
call' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:inddl_transaction’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:719:in
block in migrate' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:ineach’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in
migrate' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:570:inup’
/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/migration.rb:551:in
migrate' /opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:153:inblock (2 levels) in <top (required)>’
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:205:in call' /opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:205:inblock in execute’
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:200:in each' /opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:200:inexecute’
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:158:in block in invoke_with_call_chain' /opt/rh/ruby193/root/usr/share/ruby/monitor.rb:211:inmon_synchronize’
/opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:151:in
invoke_with_call_chain' /opt/rh/ruby193/root/usr/share/ruby/rake/task.rb:144:ininvoke’
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:116:in invoke_task' /opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:inblock (2
levels) in top_level’
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:in each' /opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:94:inblock in
top_level’
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:133:in
standard_exception_handling' /opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:88:intop_level’
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:66:in block in run' /opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:133:instandard_exception_handling’
/opt/rh/ruby193/root/usr/share/ruby/rake/application.rb:63:in run' /opt/rh/ruby193/root/usr/bin/rake:32:in'
Tasks: TOP => db:migrate

Jean-michel BARBET | Tel: +33 (0)2 51 85 84 86
Laboratoire SUBATECH Nantes France | Fax: +33 (0)2 51 85 84 79
CNRS-IN2P3/Ecole des Mines/Universite | E-Mail: barbet@subatech.in2p3.fr

> BTW, what is the difference between :
>
> a) root>sudo -u foreman '/usr/share/foreman/extras/dbmigrate
> b) root>foreman-rake db:migrate

Almost none except SCL on Red Hats, check the script out. I recommend to
use the script from now on.

> Validation failed: Owner has this role already
> /usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb:4:in

Maybe a bug?

Marek what you think? We should disable validations like we do for other
migrations.

··· -- Later,

Lukas “lzap” Zapletal
irc: lzap #theforeman

Hello,

I tried to circumvent the problem by commenting out the code in :
/usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb

The db:migrate procedure completes, so I proceeded with the upgrade:

foreman-rake db:seed
foreman-rake tmp:cache:clear
foreman-rake tmp:sessions:clear
service httpd restart

But an attempt to access the web interface produces the same kind of
error :

Web application could not be started

Validation failed: Owner has this role already (ActiveRecord::RecordInvalid)

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/validations.rb:56:in
`save!'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/attribute_methods/dirty.rb:33:in
`save!'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in
`block in save!'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:295:in
`block in with_transaction_returning_status'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in
`transaction'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:208:in
`transaction'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:293:in
`with_transaction_returning_status'

/opt/rh/ruby193/root/usr/share/gems/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in
`save!'
[…]

=> I cannot try to hack more, I do not understand what I am doing…

=> I plan to go back to my original plans which where to upgrade
Foreman from 1.1stable to 1.4 and postpone the update to 1.5.

Thank you

JM

··· On 05/12/2014 12:20 PM, Lukas Zapletal wrote:

Validation failed: Owner has this role already
/usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb:4:in

Maybe a bug?

Marek what you think? We should disable validations like we do for other
migrations.

Jean-michel BARBET | Tel: +33 (0)2 51 85 84 86
Laboratoire SUBATECH Nantes France | Fax: +33 (0)2 51 85 84 79
CNRS-IN2P3/Ecole des Mines/Universite | E-Mail: barbet@subatech.in2p3.fr

If you can inspect the database when on Foreman 1.4, look at the
user_roles table and see if there are any duplicate entries - i.e. two
records with identical owner_id and role_id specified. (Indicating a
user has a role twice, somehow.) You can safely remove duplicates and
attempt an upgrade again.

··· On 13/05/14 08:08, Jean-Michel Barbet wrote: > On 05/12/2014 12:20 PM, Lukas Zapletal wrote: > >>> Validation failed: Owner has this role already >>> /usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb:4:in >> >> Maybe a bug? >> >> Marek what you think? We should disable validations like we do for other >> migrations. > > Hello, > > I tried to circumvent the problem by commenting out the code in : > /usr/share/foreman/db/migrate/20131122093940_calculate_cache_for_user_role.rb > > The db:migrate procedure completes, so I proceeded with the upgrade: > > foreman-rake db:seed > foreman-rake tmp:cache:clear > foreman-rake tmp:sessions:clear > service httpd restart > > But an attempt to access the web interface produces the same kind of > error : > > Web application could not be started > > Validation failed: Owner has this role already (ActiveRecord::RecordInvalid)


Dominic Cleal
Red Hat Engineering

Hello,

Did it and found one duplicate. After suppression, I can access the
web interface.

Thank you Dominic.

Now I am going to replay the 1.1 to 1.5 migration from beginning
giving the new machine the same name as the previous.

JM

··· On 05/13/2014 11:54 AM, Dominic Cleal wrote:

If you can inspect the database when on Foreman 1.4, look at the
user_roles table and see if there are any duplicate entries - i.e. two
records with identical owner_id and role_id specified. (Indicating a
user has a role twice, somehow.) You can safely remove duplicates and
attempt an upgrade again.

Jean-michel BARBET | Tel: +33 (0)2 51 85 84 86
Laboratoire SUBATECH Nantes France | Fax: +33 (0)2 51 85 84 79
CNRS-IN2P3/Ecole des Mines/Universite | E-Mail: barbet@subatech.in2p3.fr