Commit bfe38dfe authored by Stan Hu's avatar Stan Hu

Clean up duplicate indexes on ci_trigger_requests

Some installations somehow gained duplicate indexes on
ci_trigger_requests.trigger_id.

As a result, upgrading to GitLab 12.4.0 may cause this error:

```
ArgumentError: Multiple indexes found on ci_trigger_requests columns
[:trigger_id]. Specify an index name from
ci_trigger_requests_trigger_id_idx, fk_rails_b8ec8b7245,
index_ci_trigger_requests_on_trigger_id
```

This error comes from ActiveRecord's `index_name_for_remove`. This
method raises this exception if the `remove_index` is ambiguous.

Since our end state is to remove all indexes on
`ci_trigger_requests.trigger_id`, find the indexes that have this
signature and pass in an explicit `name` to disambiguate the index to
drop.

Closes https://gitlab.com/gitlab-org/gitlab/issues/34818
parent 7327cfa5
---
title: Clean up duplicate indexes on ci_trigger_requests
merge_request: 19053
author:
type: fixed
......@@ -10,7 +10,12 @@ class ReplaceCiTriggerRequestsIndex < ActiveRecord::Migration[5.2]
def up
add_concurrent_index :ci_trigger_requests, [:trigger_id, :id], order: { id: :desc }
remove_concurrent_index :ci_trigger_requests, [:trigger_id]
# Some installations have legacy, duplicate indexes on
# ci_trigger_requests.trigger_id. Rails won't drop them without an
# explicit name: https://gitlab.com/gitlab-org/gitlab/issues/34818
old_index_names.each do |name|
remove_concurrent_index :ci_trigger_requests, [:trigger_id], name: name
end
end
def down
......@@ -18,4 +23,10 @@ class ReplaceCiTriggerRequestsIndex < ActiveRecord::Migration[5.2]
remove_concurrent_index :ci_trigger_requests, [:trigger_id, :id], order: { id: :desc }
end
private
def old_index_names
indexes(:ci_trigger_requests).select { |i| i.columns == ['trigger_id'] }.map(&:name)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment