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

20201030121314_schedule_update_existing_users_that_require_two_factor_auth.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2cb7c9c5250d8560619adfc9be4e3c6fa03bf66c (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
32
33
34
35
# # frozen_string_literal: true

class ScheduleUpdateExistingUsersThatRequireTwoFactorAuth < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  MIGRATION = 'UpdateExistingUsersThatRequireTwoFactorAuth'
  DELAY_INTERVAL = 2.minutes
  BATCH_SIZE = 1000
  INDEX_NAME = 'index_users_on_require_two_factor_authentication_from_group'

  disable_ddl_transaction!

  class User < ActiveRecord::Base
    include EachBatch

    self.table_name = 'users'
  end

  def up
    add_concurrent_index :users,
                         :require_two_factor_authentication_from_group,
                         where: 'require_two_factor_authentication_from_group = TRUE',
                         name: INDEX_NAME

    relation = User.where(require_two_factor_authentication_from_group: true)

    queue_background_migration_jobs_by_range_at_intervals(
      relation, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
  end

  def down
    remove_concurrent_index_by_name :users, INDEX_NAME
  end
end