Omnibus upgrade failing database migration

Hello there,

I just tried to install the latest security patch that was released today. Unfortunately, the upgrade failed leaving me with a broken GitLab installation, please help!

So I migrated GitLab from a Debian Jessie server to a Debian Buster server following the instructions. GitLab was working fine in version 13.3.9-ce.0. This is the first upgrade on the new server. Upgrade was attempted from 13.3.9-ce.0 to 13.6.2-ce.0.

Here’s the (maybe) relevant part of the log:

== 20200920130356 AddContainerExpirationPolicyWorkerSettingsToApplicationSettings: migrating 
-- column_exists?(:application_settings, :container_registry_expiration_policies_worker_capacity)
   -> 0.0370s
-- add_column(:application_settings, :container_registry_expiration_policies_worker_capacity, :integer, {:default=>0, :null=>false})rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "postgres_indexes" already exists
/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb:7:in `up'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:59:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'

Caused by:
ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR:  relation "postgres_indexes" already exists
/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb:7:in `up'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:59:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'

Caused by:
PG::DuplicateTable: ERROR:  relation "postgres_indexes" already exists
/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb:7:in `up'
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:59:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Cannot paste the whole log as that’s too long and not accepted by the forum.

Here’s the complete logfile: https://drive.google.com/file/d/1dSPIzVbTBPcMzFxuHQk1WCNvBCn6bh6-/view?usp=sharing

Any help is greatly appreciated!

Thanks in advance,
Mike

Edit: After further investigation, I suspect this might be a bug triggered through an unlucky combination of events, so I filed a bug in the GitLab issue tracker. Here’s the Link for reference: https://gitlab.com/gitlab-org/gitlab/-/issues/292240

Hi, I had the same issue, I successfully updated Gitlab after modifying /opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb file:

diff --git a/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb.orig b/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb
index c16eae4..04c64e3 100644
--- a/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb.orig
+++ b/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200922093004_add_postgres_index_view.rb
@@ -5,6 +5,7 @@ class AddPostgresIndexView < ActiveRecord::Migration[6.0]
 
   def up
     execute(<<~SQL)
+      DROP VIEW IF EXISTS postgres_indexes;
       CREATE VIEW postgres_indexes AS
       SELECT
         pg_namespace.nspname || '.' || pg_class.relname as identifier,