BigW Consortium Gitlab

20170707183807_add_group_id_to_milestones.rb 539 Bytes
Newer Older
Felipe Artur committed
1 2 3 4
class AddGroupIdToMilestones < ActiveRecord::Migration
  DOWNTIME = false

  def up
5 6
    return if column_exists? :milestones, :group_id

Felipe Artur committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20
    change_column_null :milestones, :project_id, true

    add_column :milestones, :group_id, :integer
  end

  def down
    # We cannot rollback project_id not null constraint if there are records
    # with null values.
    execute "DELETE from milestones WHERE project_id IS NULL"

    remove_column :milestones, :group_id
    change_column :milestones, :project_id, :integer, null: false
  end
end