diff options
author | Jarka Kadlecová <jarka@gitlab.com> | 2018-06-13 18:11:10 +0200 |
---|---|---|
committer | Jarka Kadlecová <jarka@gitlab.com> | 2018-07-03 09:34:44 +0200 |
commit | 57a44f2da3d2a0b59209b6c2d653d04efd0d3d41 (patch) | |
tree | 37a3035e1f1411a16a989e8b22f20bb80c79cf6d /db/migrate/20180608091413_add_group_to_todos.rb | |
parent | 275fbf24b1810e2fbef92b6599d5372855b97b46 (diff) | |
download | gitlab-ce-57a44f2da3d2a0b59209b6c2d653d04efd0d3d41.tar.gz |
Support todos for epics backport
Diffstat (limited to 'db/migrate/20180608091413_add_group_to_todos.rb')
-rw-r--r-- | db/migrate/20180608091413_add_group_to_todos.rb | 32 |
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..ca08de835a1 --- /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_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 |