summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-03-01 17:25:05 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-03-06 12:53:14 +0100
commit8a7cd25d08789ee70eaa7de3367f7ad286c49272 (patch)
treef0ebacbac31f9d7e91658cf538d5fe7dbcacf2ef /db
parent43b74afd8656df8228c19d5e5e6aee9f87abc244 (diff)
downloadgitlab-ce-8a7cd25d08789ee70eaa7de3367f7ad286c49272.tar.gz
For MySQL, foreign keys are dependent on index.
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180223120443_create_user_interacted_projects_table.rb3
-rw-r--r--db/post_migrate/20180223124427_build_user_interacted_projects_table.rb6
2 files changed, 6 insertions, 3 deletions
diff --git a/db/migrate/20180223120443_create_user_interacted_projects_table.rb b/db/migrate/20180223120443_create_user_interacted_projects_table.rb
index 8089de45666..20749940b1e 100644
--- a/db/migrate/20180223120443_create_user_interacted_projects_table.rb
+++ b/db/migrate/20180223120443_create_user_interacted_projects_table.rb
@@ -10,9 +10,6 @@ class CreateUserInteractedProjectsTable < ActiveRecord::Migration
t.references :user, null: false
t.references :project, null: false
end
-
- add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id, on_delete: :cascade
- add_concurrent_foreign_key :user_interacted_projects, :projects, column: :project_id, on_delete: :cascade
end
def down
diff --git a/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb b/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb
index 0992509c629..4d14dc7b4fb 100644
--- a/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb
+++ b/db/post_migrate/20180223124427_build_user_interacted_projects_table.rb
@@ -14,11 +14,17 @@ class BuildUserInteractedProjectsTable < ActiveRecord::Migration
end.up
add_concurrent_index :user_interacted_projects, [:project_id, :user_id], unique: true
+
+ add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id, on_delete: :cascade
+ add_concurrent_foreign_key :user_interacted_projects, :projects, column: :project_id, on_delete: :cascade
end
def down
execute "TRUNCATE user_interacted_projects"
+ remove_foreign_key :user_interacted_projects, :users
+ remove_foreign_key :user_interacted_projects, :projects
+
remove_concurrent_index_by_name :user_interacted_projects, 'index_user_interacted_projects_on_project_id_and_user_id'
end