Commit ec2dbb8f authored by Lin Jen-Shin's avatar Lin Jen-Shin

Guard the EE migration because upgrading from

CE to EE could already have run the CE migration,
making these migrations not useful anymore.
parent 492cf5ee
......@@ -2,12 +2,16 @@ class AddGroupIdToBoards < ActiveRecord::Migration
DOWNTIME = false
def up
return if group_id_exists?
change_column_null :boards, :project_id, true
add_column :boards, :group_id, :integer
end
def down
return unless group_id_exists?
# We cannot rollback project_id not null constraint if there are records
# with null values.
execute "DELETE from boards WHERE project_id IS NULL"
......@@ -15,4 +19,10 @@ class AddGroupIdToBoards < ActiveRecord::Migration
remove_column :boards, :group_id
change_column :boards, :project_id, :integer, null: false
end
private
def group_id_exists?
column_exists?(:boards, :group_id)
end
end
......@@ -6,14 +6,26 @@ class AddGroupBoardsIndexes < ActiveRecord::Migration
DOWNTIME = false
def up
return if foreign_key_exists?(:boards, :group_id)
add_concurrent_foreign_key :boards, :namespaces, column: :group_id, on_delete: :cascade
add_concurrent_index :boards, :group_id
end
def down
return unless foreign_key_exists?(:boards, :group_id)
remove_foreign_key :boards, column: :group_id
remove_concurrent_index :boards, :group_id
end
private
def foreign_key_exists?(table, column)
foreign_keys(table).any? do |key|
key.options[:column] == column.to_s
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