Improve stage_id in ci_builds foreign key migration
This commit is contained in:
parent
0f30bcf15d
commit
3bad69cc78
2 changed files with 26 additions and 9 deletions
|
@ -0,0 +1,21 @@
|
||||||
|
class AddStageIdForeignKeyToBuilds < ActiveRecord::Migration
|
||||||
|
include Gitlab::Database::MigrationHelpers
|
||||||
|
|
||||||
|
DOWNTIME = false
|
||||||
|
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def up
|
||||||
|
unless index_exists?(:ci_builds, :stage_id)
|
||||||
|
add_concurrent_index(:ci_builds, :stage_id)
|
||||||
|
add_concurrent_foreign_key(:ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade)
|
||||||
|
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
|
||||||
|
end
|
|
@ -3,19 +3,15 @@ class AddStageIdIndexToBuilds < ActiveRecord::Migration
|
||||||
|
|
||||||
DOWNTIME = false
|
DOWNTIME = false
|
||||||
|
|
||||||
disable_ddl_transaction!
|
##
|
||||||
|
# Improved in 20170703102400_add_stage_id_foreign_key_to_builds.rb
|
||||||
|
#
|
||||||
|
|
||||||
def up
|
def up
|
||||||
unless index_exists?(:ci_builds, :stage_id)
|
# noop
|
||||||
add_concurrent_foreign_key(:ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade)
|
|
||||||
add_concurrent_index(:ci_builds, :stage_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
if index_exists?(:ci_builds, :stage_id)
|
# noop
|
||||||
remove_foreign_key(:ci_builds, column: :stage_id)
|
|
||||||
remove_concurrent_index(:ci_builds, :stage_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue