summaryrefslogtreecommitdiff
path: root/db/post_migrate/20190725080128_set_not_null_on_users_private_profile.rb
blob: db42e949d3f1e6846ff81c13af0d1a8f2f54a96a (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
# frozen_string_literal: true

class SetNotNullOnUsersPrivateProfile < ActiveRecord::Migration[5.1]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    Gitlab::BackgroundMigration.steal('MigrateNullPrivateProfileToFalse')

    # rubocop:disable Migration/UpdateLargeTable
    # rubocop:disable Migration/UpdateColumnInBatches
    # Data has been migrated previously, count should be close to 0
    update_column_in_batches(:users, :private_profile, false) do |table, query|
      query.where(table[:private_profile].eq(nil))
    end

    change_column_null :users, :private_profile, false
  end

  def down
    change_column_null :users, :private_profile, true
  end
end