summaryrefslogtreecommitdiff
path: root/db/migrate/20230321113956_add_indexes_to_merge_request_compliance_violations.rb
blob: 66a24dc73c420d960517e2264d06f5d2d63c0598 (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
# frozen_string_literal: true

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

  INDEX_SEVERITY_LEVEL_DESC = 'i_compliance_violations_on_project_id_severity_and_id'
  INDEX_REASON_ASC = 'i_compliance_violations_on_project_id_reason_and_id'
  INDEX_TITLE_ASC = 'i_compliance_violations_on_project_id_title_and_id'
  INDEX_MERGED_AT_ASC = 'i_compliance_violations_on_project_id_merged_at_and_id'

  def up
    add_concurrent_index :merge_requests_compliance_violations, [:target_project_id, :severity_level, :id],
      order: { severity_level: :desc, id: :desc }, using: :btree, name: INDEX_SEVERITY_LEVEL_DESC
    add_concurrent_index :merge_requests_compliance_violations, [:target_project_id, :reason, :id],
      order: { reason: :asc, id: :asc }, using: :btree, name: INDEX_REASON_ASC
    add_concurrent_index :merge_requests_compliance_violations, [:target_project_id, :title, :id],
      order: { title: :asc, id: :asc }, using: :btree, name: INDEX_TITLE_ASC
    add_concurrent_index :merge_requests_compliance_violations, [:target_project_id, :merged_at, :id],
      order: { merged_at: :asc, id: :asc }, using: :btree, name: INDEX_MERGED_AT_ASC
  end

  def down
    remove_concurrent_index_by_name :merge_requests_compliance_violations, INDEX_TITLE_ASC
    remove_concurrent_index_by_name :merge_requests_compliance_violations, INDEX_TITLE_ASC
    remove_concurrent_index_by_name :merge_requests_compliance_violations, INDEX_SEVERITY_LEVEL_DESC
    remove_concurrent_index_by_name :merge_requests_compliance_violations, INDEX_REASON_ASC
    remove_concurrent_index_by_name :merge_requests_compliance_violations, INDEX_MERGED_AT_ASC
  end
end