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

20210611080951_fix_missing_traversal_ids.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 45728ef26f56c53c3fb43156438edce1d62eb749 (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
45
46
47
48
# frozen_string_literal: true

class FixMissingTraversalIds < ActiveRecord::Migration[6.1]
  include Gitlab::Database::MigrationHelpers

  ROOTS_MIGRATION = 'BackfillNamespaceTraversalIdsRoots'
  CHILDREN_MIGRATION = 'BackfillNamespaceTraversalIdsChildren'
  DOWNTIME = false
  BATCH_SIZE = 1_000
  SUB_BATCH_SIZE = 50
  DELAY_INTERVAL = 2.minutes
  ROOT_NS_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_root_namespaces'
  CHILD_INDEX_NAME = 'tmp_index_namespaces_empty_traversal_ids_with_child_namespaces'

  disable_ddl_transaction!

  def up
    add_concurrent_index :namespaces, :id, where: "parent_id IS NULL AND traversal_ids = '{}'", name: ROOT_NS_INDEX_NAME
    add_concurrent_index :namespaces, :id, where: "parent_id IS NOT NULL AND traversal_ids = '{}'", name: CHILD_INDEX_NAME

    # Personal namespaces and top-level groups
    final_delay = queue_background_migration_jobs_by_range_at_intervals(
      ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsRoots::Namespace.base_query.where("traversal_ids = '{}'"),
       ROOTS_MIGRATION,
       DELAY_INTERVAL,
       batch_size: BATCH_SIZE,
       other_job_arguments: [SUB_BATCH_SIZE],
       track_jobs: true
    )
    final_delay += DELAY_INTERVAL

    # Subgroups
    queue_background_migration_jobs_by_range_at_intervals(
      ::Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsChildren::Namespace.base_query.where("traversal_ids = '{}'"),
       CHILDREN_MIGRATION,
       DELAY_INTERVAL,
       batch_size: BATCH_SIZE,
       initial_delay: final_delay,
       other_job_arguments: [SUB_BATCH_SIZE],
       track_jobs: true
    )
  end

  def down
    remove_concurrent_index_by_name :namespaces, ROOT_NS_INDEX_NAME
    remove_concurrent_index_by_name :namespaces, CHILD_INDEX_NAME
  end
end