20180227182112_add_group_id_to_boards_ce.rb 821 Bytes
Newer Older
1
class AddGroupIdToBoardsCe < ActiveRecord::Migration
2 3 4 5 6 7 8
  include Gitlab::Database::MigrationHelpers

  disable_ddl_transaction!

  DOWNTIME = false

  def up
Felipe Artur's avatar
Felipe Artur committed
9 10 11 12 13
    return if group_id_exists?

    add_column :boards, :group_id, :integer
    add_foreign_key :boards, :namespaces, column: :group_id, on_delete: :cascade
    add_concurrent_index :boards, :group_id
14

Felipe Artur's avatar
Felipe Artur committed
15
    change_column_null :boards, :project_id, true
16 17 18
  end

  def down
Felipe Artur's avatar
Felipe Artur committed
19 20 21 22 23 24 25 26
    return unless group_id_exists?

    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
27 28 29 30 31 32 33 34
  end

  private

  def group_id_exists?
    column_exists?(:boards, :group_id)
  end
end