Commit c0bfe9db authored by Andreas Brandl's avatar Andreas Brandl

Patch MySQL's odd foreign key behavior.

parent 58a99463
...@@ -12,6 +12,19 @@ class AddIndexesForUserActivityQueries < ActiveRecord::Migration ...@@ -12,6 +12,19 @@ class AddIndexesForUserActivityQueries < ActiveRecord::Migration
def down def down
remove_concurrent_index :events, [:project_id, :author_id] remove_concurrent_index :events, [:project_id, :author_id]
remove_concurrent_index :user_interacted_projects, :user_id
patch_foreign_keys do
remove_concurrent_index :user_interacted_projects, :user_id
end
end
private
def patch_foreign_keys
# MySQL doesn't like to remove the index with a foreign key using it.
remove_foreign_key :user_interacted_projects, :users unless Gitlab::Database.postgresql?
yield
# Let's re-add the foreign key using the existing index on (user_id, project_id)
add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id unless Gitlab::Database.postgresql?
end end
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