2017-07-07 15:08:49 +00:00
|
|
|
class AddGroupIdToMilestones < ActiveRecord::Migration
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
def up
|
2017-07-07 18:01:30 +00:00
|
|
|
return if column_exists? :milestones, :group_id
|
|
|
|
|
2017-07-07 15:08:49 +00:00
|
|
|
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
|