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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-02-06 11:32:18 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-02-06 11:32:18 +0300
commit066d4deaed3d8698a9d1decd138871528cecc4af (patch)
treeaee535d5f19f0798ab155fdb2f65a4c743e54422 /db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb
parente011e291dadb00b260e74c25a64134f78d4d2177 (diff)
parent84bda43a3c0ce13a436748d0bc0ea943f6ebccb3 (diff)
Merge branch 'master' into fix/gb/fix-redundant-pipeline-stages
* master: (441 commits) Conflicts: db/schema.rb
Diffstat (limited to 'db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb')
-rw-r--r--db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb b/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb
new file mode 100644
index 00000000000..92c32feebf7
--- /dev/null
+++ b/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb
@@ -0,0 +1,26 @@
+class ChangeAuthorIdToNotNullInTodos < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ class Todo < ActiveRecord::Base
+ self.table_name = 'todos'
+ include EachBatch
+ end
+
+ BATCH_SIZE = 1000
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ Todo.where(author_id: nil).each_batch(of: BATCH_SIZE) do |batch|
+ batch.delete_all
+ end
+
+ change_column_null :todos, :author_id, false
+ end
+
+ def down
+ change_column_null :todos, :author_id, true
+ end
+end