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

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

class AddTemporaryIndexesForOrphanedApprovalRules < Gitlab::Database::Migration[2.1]
  disable_ddl_transaction!

  LICENSE_SCANNING = 2
  SCAN_FINDING = 4

  TMP_PROJECT_INDEX_NAME = 'tmp_idx_orphaned_approval_project_rules'
  TMP_MR_INDEX_NAME = 'tmp_idx_orphaned_approval_merge_request_rules'

  def up
    add_concurrent_index('approval_project_rules', :id, where: query_condition, name: TMP_PROJECT_INDEX_NAME)
    add_concurrent_index('approval_merge_request_rules', :id, where: query_condition, name: TMP_MR_INDEX_NAME)
  end

  def down
    remove_concurrent_index_by_name('approval_project_rules', TMP_PROJECT_INDEX_NAME)
    remove_concurrent_index_by_name('approval_merge_request_rules', TMP_MR_INDEX_NAME)
  end

  private

  def query_condition
    "report_type IN (#{LICENSE_SCANNING}, #{SCAN_FINDING}) AND security_orchestration_policy_configuration_id IS NULL"
  end
end