12.2.5 -> 12.3.1 Database migration failed: Multiple indexes found
Summary
When updating my installation from source (on Archlinux) from 12.2.5 to 12.3.1 the database migration failed:
# su - gitlab -s /bin/sh -c "cd /usr/share/webapps/gitlab; EXECJS_RUNTIME=Disabled bundle-2.5 exec rake db:migrate RAILS_ENV=production"
== 20190805140353 RemoveRendundantIndexFromReleases: migrating ================
-- transaction_open?()
-> 0.0000s
-- select_one("SELECT current_setting('server_version_num') AS v")
-> 0.0105s
-- index_exists?(:releases, :project_id, {:algorithm=>:concurrently})
-> 0.0098s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- remove_index(:releases, {:algorithm=>:concurrently, :column=>:project_id})
-- execute("RESET ALL")
-> 0.0003s
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Multiple indexes found on releases columns [:project_id]. Specify an index name from index_releases_on_project_id, releases_project_id_idx
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:1243:in `index_name_for_remove'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql/schema_statements.rb:485:in `remove_index'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:871:in `block in method_missing'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `block in say_with_time'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:840:in `say_with_time'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:860:in `method_missing'
/usr/share/webapps/gitlab/lib/gitlab/database/migration_helpers.rb:121:in `block in remove_concurrent_index'
/usr/share/webapps/gitlab/lib/gitlab/database/migration_helpers.rb:252:in `disable_statement_timeout'
/usr/share/webapps/gitlab/lib/gitlab/database/migration_helpers.rb:120:in `remove_concurrent_index'
/usr/share/webapps/gitlab/db/migrate/20190805140353_remove_rendundant_index_from_releases.rb:15:in `up'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:817:in `exec_migration'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:798:in `block (2 levels) in migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:797:in `block in migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `with_connection'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:796:in `migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:977:in `migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1292:in `block in execute_migration_in_transaction'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1345:in `ddl_transaction'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1291:in `execute_migration_in_transaction'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1263:in `block in migrate_without_lock'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `each'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1262:in `migrate_without_lock'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `block in migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1363:in `with_advisory_lock'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1210:in `migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1036:in `up'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:1011:in `migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:172:in `migrate'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:60:in `block (2 levels) in <top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
This results in a status 500 error on the issue pages, similar to the problems reported here.
What is the current bug behavior?
The database migration fails.
What is the expected correct behavior?
The database migration succeeds.
Logs
/var/log/gitlab/production.log
Started GET "/bapc/2019/issues/64" for ::ffff:212.51.151.240 at 2019-09-30 21:38:57 +0200
Processing by Projects::IssuesController#show as HTML
Parameters: {"namespace_id"=>"bapc", "project_id"=>"2019", "id"=>"64"}
Completed 500 Internal Server Error in 105ms (ActiveRecord: 9.8ms | Elasticsearch: 0.0ms)
ActionView::Template::Error (undefined local variable or method `duplicated_to_id' for #<Issue id:831 bapc/2019#64>
Did you mean? duplicated_to
duplicated_to=):
15: .issuable-status-box.status-box.status-box-issue-closed{ class: issue_status_visibility(@issue, status_box: :closed) }
16: = sprite_icon('mobile-issue-close', size: 16, css_class: 'd-block d-sm-none')
17: .d-none.d-sm-block
18: = issue_closed_text(@issue, current_user)
19: .issuable-status-box.status-box.status-box-open{ class: issue_status_visibility(@issue, status_box: :open) }
20: = sprite_icon('issue-open-m', size: 16, css_class: 'd-block d-sm-none')
21: %span.d-none.d-sm-block Open
app/models/issue.rb:186:in `duplicated?'
app/helpers/issues_helper.rb:165:in `issue_closed_link'
app/helpers/issues_helper.rb:171:in `issue_closed_text'
app/views/projects/issues/show.html.haml:18:in `_app_views_projects_issues_show_html_haml___890608939632890174_47197970261020'
app/controllers/application_controller.rb:118:in `render'
app/controllers/concerns/issuable_actions.rb:33:in `block (2 levels) in show'
app/controllers/concerns/issuable_actions.rb:30:in `show'
lib/gitlab/session.rb:11:in `with_session'
app/controllers/application_controller.rb:450:in `set_session_storage'
lib/gitlab/i18n.rb:55:in `with_locale'
lib/gitlab/i18n.rb:61:in `with_user_locale'
app/controllers/application_controller.rb:444:in `set_locale'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/correlation_id.rb:16:in `block in call'
lib/gitlab/middleware/correlation_id.rb:15:in `call'
lib/gitlab/middleware/multipart.rb:117:in `call'
lib/gitlab/middleware/read_only/controller.rb:42:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:26:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:29:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
Started GET "/favicon.ico" for ::ffff:212.51.151.240 at 2019-09-30 21:38:57 +0200
\d releases
in postgres:
Column | Type | Collation | Nullable | Default
-------------------------+--------------------------+-----------+----------+--------------------------------------
id | integer | | not null | nextval('releases_id_seq'::regclass)
tag | character varying(510) | | | NULL::character varying
description | text | | |
project_id | integer | | |
created_at | timestamp with time zone | | |
updated_at | timestamp with time zone | | |
description_html | text | | |
cached_markdown_version | integer | | |
author_id | integer | | |
name | character varying | | |
sha | character varying | | |
released_at | timestamp with time zone | | not null |
Indexes:
"releases_pkey" PRIMARY KEY, btree (id)
"index_releases_on_author_id" btree (author_id)
"index_releases_on_project_id" btree (project_id)
"index_releases_on_project_id_and_tag" btree (project_id, tag)
"releases_project_id_idx" btree (project_id)
Recent upgrade history:
upgraded gitlab (11.10.4-1 -> 12.0.0-1)
upgraded gitlab (12.0.0-1 -> 12.0.3-1)
upgraded gitlab (12.0.3-1 -> 12.1.2-1)
upgraded gitlab (12.1.2-1 -> 12.2.1-1)
upgraded gitlab (12.2.1-1 -> 12.2.5-1)
upgraded gitlab (12.2.5-1 -> 12.3.1-1)
Fix
Looking at db/schema.rb
neither of the two (project_id)
indexes is needed anymore.
Running DROP INDEX index_releases_on_project_id;
to drop one of the two (project_id)
indexes makes the migration succeed and continue (successfully) with all remaining migrations.
Edited by 🤖 GitLab Bot 🤖