2018-12-23 12:14:25 +05:30
|
|
|
class AddGroupIdToBoardsCe < ActiveRecord::Migration[4.2]
|
2018-03-27 19:54:05 +05:30
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
def up
|
|
|
|
return if group_id_exists?
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
# rubocop:disable Migration/AddConcurrentForeignKey
|
2018-03-27 19:54:05 +05:30
|
|
|
add_column :boards, :group_id, :integer
|
|
|
|
add_foreign_key :boards, :namespaces, column: :group_id, on_delete: :cascade
|
|
|
|
add_concurrent_index :boards, :group_id
|
|
|
|
|
|
|
|
change_column_null :boards, :project_id, true
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
return unless group_id_exists?
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
# rubocop:disable Migration/RemoveIndex
|
2018-03-27 19:54:05 +05:30
|
|
|
remove_foreign_key :boards, column: :group_id
|
|
|
|
remove_index :boards, :group_id if index_exists? :boards, :group_id
|
|
|
|
remove_column :boards, :group_id
|
|
|
|
|
|
|
|
execute "DELETE from boards WHERE project_id IS NULL"
|
|
|
|
change_column_null :boards, :project_id, false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_id_exists?
|
|
|
|
column_exists?(:boards, :group_id)
|
|
|
|
end
|
|
|
|
end
|