Commit d9462f4d authored by Jarka Košanová's avatar Jarka Košanová

Split migration into adding column and adding FK

parent d2ad55fa
...@@ -7,23 +7,11 @@ class AddParentToEpic < ActiveRecord::Migration[5.0] ...@@ -7,23 +7,11 @@ class AddParentToEpic < ActiveRecord::Migration[5.0]
DOWNTIME = false DOWNTIME = false
disable_ddl_transaction!
def up def up
add_column :epics, :parent_id, :integer unless parent_id_exists? add_column :epics, :parent_id, :integer
add_concurrent_foreign_key :epics, :epics, column: :parent_id, on_delete: :cascade
add_concurrent_index :epics, :parent_id
end end
def down def down
remove_foreign_key_without_error(:epics, column: :parent_id) remove_column :epics, :parent_id
remove_concurrent_index(:epics, :parent_id)
remove_column(:epics, :parent_id) if parent_id_exists?
end
private
def parent_id_exists?
column_exists?(:epics, :parent_id)
end end
end end
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddParentEpicFk < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_foreign_key :epics, :epics, column: :parent_id, on_delete: :cascade
add_concurrent_index :epics, :parent_id
end
def down
remove_foreign_key :epics, column: :parent_id
remove_concurrent_index :epics, :parent_id
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