summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb')
-rw-r--r--db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb b/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb
new file mode 100644
index 00000000000..5cffdb641d6
--- /dev/null
+++ b/db/post_migrate/20220505174658_update_index_on_alerts_to_exclude_null_fingerprints.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class UpdateIndexOnAlertsToExcludeNullFingerprints < Gitlab::Database::Migration[2.0]
+ disable_ddl_transaction!
+
+ OLD_INDEX_NAME = 'index_partial_am_alerts_on_project_id_and_fingerprint'
+ NEW_INDEX_NAME = 'index_unresolved_alerts_on_project_id_and_fingerprint'
+
+ def up
+ add_concurrent_index :alert_management_alerts,
+ [:project_id, :fingerprint],
+ where: "fingerprint IS NOT NULL and status <> 2",
+ name: NEW_INDEX_NAME,
+ unique: true
+
+ remove_concurrent_index_by_name :alert_management_alerts, OLD_INDEX_NAME
+ end
+
+ def down
+ add_concurrent_index :alert_management_alerts,
+ [:project_id, :fingerprint],
+ where: "status <> 2",
+ name: OLD_INDEX_NAME,
+ unique: true
+
+ remove_concurrent_index_by_name :alert_management_alerts, NEW_INDEX_NAME
+ end
+end