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

20221115173607_ensure_work_item_type_backfill_migration_finished.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2cec1919e82483a142d94f43eee63f1877967432 (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
# frozen_string_literal: true

class EnsureWorkItemTypeBackfillMigrationFinished < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  MIGRATION = 'BackfillWorkItemTypeIdForIssues'

  class MigrationWorkItemType < MigrationRecord
    self.table_name = 'work_item_types'

    def self.id_by_type(types)
      where(namespace_id: nil, base_type: types).pluck(:base_type, :id).to_h
    end
  end

  def up
    # more types were added to the types table after the backfill run
    # so we cannot fetch all from the DB but only those that were backfilled
    relevant_types = {
      issue: 0,
      incident: 1,
      test_case: 2,
      requirement: 3,
      task: 4
    }

    MigrationWorkItemType.id_by_type(relevant_types.values).each do |base_type, type_id|
      ensure_batched_background_migration_is_finished(
        job_class_name: MIGRATION,
        table_name: :issues,
        column_name: :id,
        job_arguments: [base_type, type_id]
      )
    end
  end

  def down
    # noop
  end
end