diff options
Diffstat (limited to 'db/migrate/20230321113956_add_indexes_to_merge_request_compliance_violations.rb')
-rw-r--r-- | db/migrate/20230321113956_add_indexes_to_merge_request_compliance_violations.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/db/migrate/20230321113956_add_indexes_to_merge_request_compliance_violations.rb b/db/migrate/20230321113956_add_indexes_to_merge_request_compliance_violations.rb new file mode 100644 index 00000000000..66a24dc73c4 --- /dev/null +++ b/db/migrate/20230321113956_add_indexes_to_merge_request_compliance_violations.rb @@ -0,0 +1,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 |