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

20191007163736_populate_remaining_any_approver_rules_for_projects.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fce17ffcf16ce075de3c55711a2c4c4673504ecb (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
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

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

  DOWNTIME = false
  BATCH_SIZE = 5_000
  MIGRATION = 'PopulateAnyApprovalRuleForProjects'

  disable_ddl_transaction!

  class Project < ActiveRecord::Base
    include EachBatch

    self.table_name = 'projects'

    scope :with_approvals_before_merge, -> { where.not(approvals_before_merge: 0) }
  end

  def up
    return unless Gitlab.ee?

    add_concurrent_index :projects, :id,
      name: 'tmp_projects_with_approvals_before_merge',
      where: 'approvals_before_merge != 0'

    Gitlab::BackgroundMigration.steal(MIGRATION)

    PopulateRemainingAnyApproverRulesForProjects::Project.with_approvals_before_merge.each_batch(of: BATCH_SIZE) do |batch|
      range = batch.pluck('MIN(id)', 'MAX(id)').first

      Gitlab::BackgroundMigration::PopulateAnyApprovalRuleForProjects.new.perform(*range)
    end

    remove_concurrent_index_by_name(:projects, 'tmp_projects_with_approvals_before_merge')
  end

  def down
    # no-op
  end
end