2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class DropForkedProjectLinksFk < ActiveRecord::Migration[6.0]
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
2020-04-22 19:07:51 +05:30
|
|
|
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
|
2020-04-08 14:13:33 +05:30
|
|
|
with_lock_retries do
|
|
|
|
remove_foreign_key_if_exists :forked_project_links, column: :forked_to_project_id
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
# rubocop: enable Migration/WithLockRetriesWithoutDdlTransaction
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
unless foreign_key_exists?(:forked_project_links, :projects, column: :forked_to_project_id)
|
2020-04-22 19:07:51 +05:30
|
|
|
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
|
2020-04-08 14:13:33 +05:30
|
|
|
with_lock_retries do
|
|
|
|
# rubocop: disable Migration/AddConcurrentForeignKey
|
|
|
|
add_foreign_key :forked_project_links, :projects, column: :forked_to_project_id, on_delete: :cascade, validate: false
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
# rubocop: enable Migration/WithLockRetriesWithoutDdlTransaction
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
fk_name = concurrent_foreign_key_name(:forked_project_links, :forked_to_project_id, prefix: 'fk_rails_')
|
|
|
|
validate_foreign_key(:forked_project_links, :forked_to_project_id, name: fk_name)
|
|
|
|
end
|
|
|
|
end
|