summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorJarka Kadlecová <jarka@gitlab.com>2018-07-16 15:35:19 +0200
committerJarka Kadlecová <jarka@gitlab.com>2018-08-02 10:42:45 +0200
commit15179878d57addb010b5afeadd4bde8b62ef3acb (patch)
treeaad121955d9ab691584613e3aea20a1b9c5eeaea /db/migrate
parent0233fffe283857d9934460625f9c17fcd278536b (diff)
downloadgitlab-ce-15179878d57addb010b5afeadd4bde8b62ef3acb.tar.gz
Revert "Revert "Merge branch 'ee-5481-epic-todos' into 'master'""
This reverts commit 8717c7dad9b5a8fa21ec9a652c54718a6b4c2175.
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20180608091413_add_group_to_todos.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/db/migrate/20180608091413_add_group_to_todos.rb b/db/migrate/20180608091413_add_group_to_todos.rb
new file mode 100644
index 00000000000..af3ee48b29d
--- /dev/null
+++ b/db/migrate/20180608091413_add_group_to_todos.rb
@@ -0,0 +1,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