summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-03-01 11:00:34 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2018-03-01 11:00:34 +0200
commitba2f8a6c7d691ec0f0178ce688e7a6d750c28d3a (patch)
tree3bf3787867359fe4f2aa9f37646ef1510e437b0a
parent71545ca633fc66e40d05256083503ea9f97cdf1e (diff)
downloadgitlab-ce-dz-namespace-id-not-null.tar.gz
Make project#namespace_id not nulldz-namespace-id-not-null
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb b/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb
new file mode 100644
index 00000000000..0342372cbed
--- /dev/null
+++ b/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb
@@ -0,0 +1,29 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class ChangeProjectNamespaceIdNotNull < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ class Project < ActiveRecord::Base
+ self.table_name = 'projects'
+ include EachBatch
+ end
+
+ BATCH_SIZE = 1000
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ Project.where(namespace_id: nil).each_batch(of: BATCH_SIZE) do |batch|
+ batch.delete_all
+ end
+
+ change_column_null :projects, :namespace_id, false
+ end
+
+ def down
+ change_column_null :projects, :namespace_id, true
+ end
+end