2018-11-13 07:27:31 +00:00
|
|
|
class AddStageIdForeignKeyToBuilds < ActiveRecord::Migration[4.2]
|
2017-07-03 18:24:32 +00:00
|
|
|
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)
|
2017-07-04 10:40:45 +00:00
|
|
|
end
|
|
|
|
|
2018-03-20 14:50:07 +00:00
|
|
|
unless foreign_key_exists?(:ci_builds, :ci_stages, column: :stage_id)
|
2017-07-03 18:24:32 +00:00
|
|
|
add_concurrent_foreign_key(:ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2018-03-20 14:50:07 +00:00
|
|
|
if foreign_key_exists?(:ci_builds, column: :stage_id)
|
2017-07-03 18:24:32 +00:00
|
|
|
remove_foreign_key(:ci_builds, column: :stage_id)
|
2017-07-04 10:40:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if index_exists?(:ci_builds, :stage_id)
|
2017-07-03 18:24:32 +00:00
|
|
|
remove_concurrent_index(:ci_builds, :stage_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|