summaryrefslogtreecommitdiff
path: root/db/post_migrate/20190812070645_migrate_private_profile_nulls.rb
blob: 063c1e16c274c7e8e51174830d2ed8a20e8482f8 (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
30
31
# frozen_string_literal: true

class MigratePrivateProfileNulls < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  DELAY = 5.minutes.to_i
  BATCH_SIZE = 1_000

  disable_ddl_transaction!

  class User < ActiveRecord::Base
    self.table_name = 'users'

    include ::EachBatch
  end

  def up
    # Migration will take about 7 hours
    User.where(private_profile: nil).each_batch(of: BATCH_SIZE) do |batch, index|
      range = batch.pluck(Arel.sql("MIN(id)"), Arel.sql("MAX(id)")).first
      delay = index * DELAY

      BackgroundMigrationWorker.perform_in(delay.seconds, 'MigrateNullPrivateProfileToFalse', [*range])
    end
  end

  def down
    # noop
  end
end