summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorJarka Kadlecová <jarka@gitlab.com>2018-08-06 11:05:44 +0200
committerJarka Kadlecová <jarka@gitlab.com>2018-08-06 14:18:21 +0200
commit6dc7490789237a84b66baaaf4c6deea5ec3bf2de (patch)
tree0753dac4c896896eeae88a3aa0f92de433839e9f /db
parent02b077925dedca390be3e8c4c7960d89ea8d4c6e (diff)
downloadgitlab-ce-6dc7490789237a84b66baaaf4c6deea5ec3bf2de.tar.gz
Add changes from the EE
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180608091413_add_group_to_todos.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/db/migrate/20180608091413_add_group_to_todos.rb b/db/migrate/20180608091413_add_group_to_todos.rb
index af3ee48b29d..20ba4849057 100644
--- a/db/migrate/20180608091413_add_group_to_todos.rb
+++ b/db/migrate/20180608091413_add_group_to_todos.rb
@@ -5,8 +5,14 @@ class AddGroupToTodos < ActiveRecord::Migration
disable_ddl_transaction!
+ class Todo < ActiveRecord::Base
+ self.table_name = 'todos'
+
+ include ::EachBatch
+ end
+
def up
- add_column :todos, :group_id, :integer
+ add_column(:todos, :group_id, :integer) unless group_id_exists?
add_concurrent_foreign_key :todos, :namespaces, column: :group_id, on_delete: :cascade
add_concurrent_index :todos, :group_id
@@ -14,13 +20,11 @@ class AddGroupToTodos < ActiveRecord::Migration
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
+ remove_foreign_key_without_error(:todos, column: :group_id)
+ remove_concurrent_index(:todos, :group_id)
+ remove_column(:todos, :group_id) if group_id_exists?
- execute "DELETE FROM todos WHERE project_id IS NULL"
+ Todo.where(project_id: nil).each_batch { |batch| batch.delete_all }
change_column_null :todos, :project_id, false
end