Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20170707183807_add_group_id_to_milestones.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 675ffd4a1c92f1fbece23dc3c1053179044bfc43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class AddGroupIdToMilestones < ActiveRecord::Migration
  DOWNTIME = false

  def up
    return if column_exists? :milestones, :group_id

    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