Bug #32657
closedUpgrade fails with error Validation failed: Name has already been taken at db:seed stage
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1954021
Description of problem:
Red Hat Satellite 6.8 minor upgrade fails with error Validation failed: Name has already been taken at db:migrate state
Version-Release number of selected component (if applicable):
6.8.z
Steps to Reproduce:
=> Execute the command to do a minor update
- satellite-maintain upgrade run --target-version 6.8.z
Actual results:
=> The satellite installer fails with the below error:-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-04-27 00:15:44 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:seed]/Exec[foreman-rake-db:seed]: Failed to call refresh: '/usr/sbin/foreman-rake db:seed' returned 1 instead of one of [0]
2021-04-27 00:15:44 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:seed]/Exec[foreman-rake-db:seed]: '/usr/sbin/foreman-rake db:seed' returned 1 instead of one of [0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expected results:
The upgrade should be completed.
Additional info:
The issue seems to be with duplicate templete.
Workaround to fix the issue:-
============================
=> Execute the query to list the templates:-
- su - postgres -c "echo \"SELECT a.* FROM templates a JOIN (SELECT name, COUNT() FROM templates GROUP BY name HAVING count() > 1 ) b ON a.name = b.name ORDER BY a.name;\" | psql foreman"
=> Identify the duplicate template:-
- awk
F\| '{print $1, $2, $8, $11, $6}' '/home/sadas/Downloads/foreman.txt' | grep "\S"---------------------------------------------------------------------------------+
id name locked type created_at
----
297 Host - Last Checkin t ReportTemplate 2021-04-26 21:03:44.527975 ===> The issue seems to be with these duplicate templates(id 297 and 296).
296 Host - Last Checkin t ReportTemplate 2021-04-26 21:03:44.508732
59 Jumpstart default t Ptable 2017-08-08 07:47:49.520343
21 Jumpstart default t ProvisioningTemplate 2017-08-08 07:47:48.798974
61 Kickstart default t Ptable 2017-08-08 07:47:49.549152
206 Kickstart default t ProvisioningTemplate 2020-01-29 09:00:56.526946
30 Preseed default t ProvisioningTemplate 2017-08-08 07:47:48.945963
62 Preseed default t Ptable 2017-08-08 07:47:49.563543
------------+--------------------+----------------------------+-------------------------+
=> Execute the command to unlock the template:- // Take a snapshot only then proceed with the next steps.
- su - postgres -c "echo \"update templates set locked = 'f' where id='297';\" | psql foreman"
=> Run the following and verify the output shows one of the entities of "Host - Last Checkin"
- su - postgres -c "echo \"select id, name, type from templates where id='297';\" | psql foreman"
If looks okay, then rename the duplicate using the below query:-
- su - postgres -c "echo \"update templates set name = 'Host - Last Checkin 2' where id='297';\" | psql foreman"
Following should now have named as "Host - Last Checkin 2"
- su - postgres -c "echo \"select id, name, type from templates where id='297';\" | psql foreman"
Then rerun the satellite-installer to complete the minor update.
Updated by Tomer Brisker over 3 years ago
- Subject changed from Red Hat Satellite 6.8 minor upgrade fails with error Validation failed: Name has already been taken at db:seed stage to Upgrade fails with error Validation failed: Name has already been taken at db:seed stage
- Category changed from Statistics to Templates
Templates do not have a unique constraint on name in the DB, causing potential race condition that allows duplicates to be created. Any duplicates should be removed and an index added.
Updated by The Foreman Bot over 3 years ago
- Status changed from New to Ready For Testing
- Assignee set to Tomer Brisker
- Pull request https://github.com/theforeman/foreman/pull/8552 added
Updated by Tomer Brisker over 3 years ago
- Related to Bug #32086: db seed triggered by sidekiq resulting in duplicate provisioning-templates added
Updated by Tomer Brisker over 3 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset foreman|5c92f9765937c3ed1f5f7bc7ac173db9009bc6a3.
Updated by Tomer Brisker over 3 years ago
- Fixed in Releases 2.5.0 added
- Fixed in Releases deleted (
3.0.0)