summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180301084653_change_project_namespace_id_not_null.rb
blob: 0342372cbed1590f994797c5b0ca8eee5db97b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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