Skip to content

Add migration to fix a merge_requests index

Yorick Peterse requested to merge redo-changelog-index into master

What does this MR do?

In !52116 (merged) we introduced a new index used when generating changelogs using the GitLab API. This migration failed in staging and production, but due to https://github.com/lfittl/pg_query/issues/184 the original error is masked, and an INVALID index is left behind.

This commit turns the old migration into a noop, and creates a new migration. This new migration catches any CREATE INDEX errors and raises a regular error, preventing the pg_query bug from surfacing. It also removes the existing index if it's marked as INVALID. In addition, we disable statement timeouts when creating the index; something we forgot to do in the previous migration.

Migration output

Migrating up:

== 20210201140434 AddOldestMergeRequestsIndexAgain: migrating =================
-- execute("SELECT pg_class.relname\nFROM pg_class, pg_index\nWHERE pg_index.indisvalid = false\nAND pg_index.indexrelid = pg_class.oid\nAND pg_class.relname = 'index_on_merge_requests_for_latest_diffs';\n")
   -> 0.0006s
-- indexes("merge_requests")
   -> 0.0047s
-- current_schema()
   -> 0.0001s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- execute("CREATE INDEX CONCURRENTLY index_on_merge_requests_for_latest_diffs ON merge_requests USING btree (target_project_id) INCLUDE (id, latest_merge_request_diff_id)")
   -> 0.0122s
-- execute("RESET ALL")
   -> 0.0002s
-- execute("COMMENT ON INDEX index_on_merge_requests_for_latest_diffs IS 'Index used to efficiently obtain the oldest merge request for a commit SHA'")
   -> 0.0015s
== 20210201140434 AddOldestMergeRequestsIndexAgain: migrated (0.0208s) ========

Migrating down:

== 20210201140434 AddOldestMergeRequestsIndexAgain: reverting =================
-- indexes("merge_requests")
   -> 0.0070s
-- execute("DROP INDEX CONCURRENTLY index_on_merge_requests_for_latest_diffs")
   -> 0.0027s
== 20210201140434 AddOldestMergeRequestsIndexAgain: reverted (0.0097s) ========

Does this MR meet the acceptance criteria?

Conformity

Edited by Yorick Peterse

Merge request reports