summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-03-20 21:02:04 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-03-21 13:41:24 +0100
commitc0bfe9db5f90ee7f07c371af8e23744b60e04815 (patch)
tree8b35eaaa8c5aa0535019660892a44f6b4ab1c32f /db/migrate
parent58a99463b6ee8f643541b42e61be15237ff35a03 (diff)
downloadgitlab-ce-c0bfe9db5f90ee7f07c371af8e23744b60e04815.tar.gz
Patch MySQL's odd foreign key behavior.
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20180320182229_add_indexes_for_user_activity_queries.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/db/migrate/20180320182229_add_indexes_for_user_activity_queries.rb b/db/migrate/20180320182229_add_indexes_for_user_activity_queries.rb
index 3232d5fe1e5..4baf8146b64 100644
--- a/db/migrate/20180320182229_add_indexes_for_user_activity_queries.rb
+++ b/db/migrate/20180320182229_add_indexes_for_user_activity_queries.rb
@@ -12,6 +12,19 @@ class AddIndexesForUserActivityQueries < ActiveRecord::Migration
def down
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