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

20180608091413_add_group_to_todos.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af3ee48b29df8e9a1c7ab3fd3d2e9cdc1ab3e5e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class AddGroupToTodos < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    add_column :todos, :group_id, :integer
    add_concurrent_foreign_key :todos, :namespaces, column: :group_id, on_delete: :cascade
    add_concurrent_index :todos, :group_id

    change_column_null :todos, :project_id, true
  end

  def down
    return unless group_id_exists?

    remove_foreign_key :todos, column: :group_id
    remove_index :todos, :group_id if index_exists?(:todos, :group_id)
    remove_column :todos, :group_id

    execute "DELETE FROM todos WHERE project_id IS NULL"
    change_column_null :todos, :project_id, false
  end

  private

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