summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-21 11:02:18 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-06-21 13:18:38 +0200
commit885d63d9ed5802803fa4797e63f4f7e02c5a73ab (patch)
tree67f5780dc9d826246969495056718f497b0a1705
parent6b9608e13e20fe579b861b911880603a372f2f27 (diff)
downloadgitlab-ce-885d63d9ed5802803fa4797e63f4f7e02c5a73ab.tar.gz
Fix adding/removing foreign keys on MySQL
-rw-r--r--db/migrate/20170526185602_add_stage_id_to_ci_builds.rb4
-rw-r--r--db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb1
-rw-r--r--db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb2
3 files changed, 3 insertions, 4 deletions
diff --git a/db/migrate/20170526185602_add_stage_id_to_ci_builds.rb b/db/migrate/20170526185602_add_stage_id_to_ci_builds.rb
index 2eeb2c481eb..d27cba76d81 100644
--- a/db/migrate/20170526185602_add_stage_id_to_ci_builds.rb
+++ b/db/migrate/20170526185602_add_stage_id_to_ci_builds.rb
@@ -3,15 +3,11 @@ class AddStageIdToCiBuilds < ActiveRecord::Migration
DOWNTIME = false
- disable_ddl_transaction!
-
def up
add_column :ci_builds, :stage_id, :integer
- add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade
end
def down
- remove_foreign_key :ci_builds, column: :stage_id
remove_column :ci_builds, :stage_id, :integer
end
end
diff --git a/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb b/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb
index a2c0b0c651b..3879cf9133b 100644
--- a/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb
+++ b/db/post_migrate/20170526185901_remove_stage_id_index_from_builds.rb
@@ -7,6 +7,7 @@ class RemoveStageIdIndexFromBuilds < ActiveRecord::Migration
def up
if index_exists?(:ci_builds, :stage_id)
+ remove_foreign_key(:ci_builds, column: :stage_id)
remove_concurrent_index(:ci_builds, :stage_id)
end
end
diff --git a/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb b/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb
index acbe16812d2..7d6609b18bf 100644
--- a/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb
+++ b/db/post_migrate/20170621102400_add_stage_id_index_to_builds.rb
@@ -7,12 +7,14 @@ class AddStageIdIndexToBuilds < ActiveRecord::Migration
def up
unless index_exists?(:ci_builds, :stage_id)
+ add_concurrent_foreign_key(:ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade)
add_concurrent_index(:ci_builds, :stage_id)
end
end
def down
if index_exists?(:ci_builds, :stage_id)
+ remove_foreign_key(:ci_builds, column: :stage_id)
remove_concurrent_index(:ci_builds, :stage_id)
end
end