Commit 885d63d9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix adding/removing foreign keys on MySQL

parent 6b9608e1
...@@ -3,15 +3,11 @@ class AddStageIdToCiBuilds < ActiveRecord::Migration ...@@ -3,15 +3,11 @@ class AddStageIdToCiBuilds < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
disable_ddl_transaction!
def up def up
add_column :ci_builds, :stage_id, :integer add_column :ci_builds, :stage_id, :integer
add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade
end end
def down def down
remove_foreign_key :ci_builds, column: :stage_id
remove_column :ci_builds, :stage_id, :integer remove_column :ci_builds, :stage_id, :integer
end end
end end
...@@ -7,6 +7,7 @@ class RemoveStageIdIndexFromBuilds < ActiveRecord::Migration ...@@ -7,6 +7,7 @@ class RemoveStageIdIndexFromBuilds < ActiveRecord::Migration
def up def up
if index_exists?(:ci_builds, :stage_id) if index_exists?(:ci_builds, :stage_id)
remove_foreign_key(:ci_builds, column: :stage_id)
remove_concurrent_index(:ci_builds, :stage_id) remove_concurrent_index(:ci_builds, :stage_id)
end end
end end
......
...@@ -7,12 +7,14 @@ class AddStageIdIndexToBuilds < ActiveRecord::Migration ...@@ -7,12 +7,14 @@ class AddStageIdIndexToBuilds < ActiveRecord::Migration
def up def up
unless index_exists?(:ci_builds, :stage_id) 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) add_concurrent_index(:ci_builds, :stage_id)
end end
end end
def down def down
if index_exists?(:ci_builds, :stage_id) if index_exists?(:ci_builds, :stage_id)
remove_foreign_key(:ci_builds, column: :stage_id)
remove_concurrent_index(:ci_builds, :stage_id) remove_concurrent_index(:ci_builds, :stage_id)
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