Column `ci_sources_pipelines` indexes do not exist and upgrade to 16.5 fails

Summary

A number of customers have encountered DB migration issues when migrating to 16.5.1 or 16.5. Reconfigure failed and background migrations could not proceed with the errors:

Caused by:
PG::UndefinedTable: ERROR:  relation "index_ci_sources_pipelines_on_pipeline_id" does not exist

and

PG: :UndefinedTable: ERROR:
relation "index_ci_sources_pipelines_on_source_pipeline_id" does not exist

There are two missing indexes that were added in this Issue - "Prepare indexes for bigint ci_sources_pipelines".

Steps to reproduce

I haven't yet reproduced this but the customers in these tickets have faced it.

[Internal access only]

Example Project

What is the current bug behavior?

What is the expected correct behavior?

Have successful database migrations with the necessary indexes.

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

To solve this, they were added manually:

#confirm table status:
gitlab-psql
\d public.ci_sources_pipelines

#If missing, add
CREATE INDEX index_ci_sources_pipelines_on_source_pipeline_id ON ci_sources_pipelines USING btree (source_pipeline_id);
CREATE INDEX index_ci_sources_pipelines_on_pipeline_id ON ci_sources_pipelines USING btree (pipeline_id);

#run db-migrate
gitlab-rake db:migrate
gitlab-rake db:migrate:status
Edited by Manuel Grabowski