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

20211101222614_consume_remaining_user_namespace_jobs.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ded9e717bb19382391b328ab716fab63c16fdcb2 (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 ConsumeRemainingUserNamespaceJobs < Gitlab::Database::Migration[1.0]
  MIGRATION = 'BackfillUserNamespace'
  BATCH_SIZE = 200
  DEFAULT_VALUE = 'User'

  disable_ddl_transaction!

  def up
    Gitlab::BackgroundMigration.steal(MIGRATION)

    # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low.
    define_batchable_model('namespaces').where(type: nil).each_batch(of: BATCH_SIZE) do |batch|
      min, max = batch.pluck('MIN(id), MAX(id)').flatten

      Gitlab::BackgroundMigration::BackfillUserNamespace.new.perform(min, max, :namespaces, :id, BATCH_SIZE, 0)
    end

    change_column_null :namespaces, :type, false
  end

  def down
    change_column_null :namespaces, :type, true
  end
end