Commit 38f5aa1c authored by Sean Arnold's avatar Sean Arnold

Add less-strict index for alert fingerprints

- Adjust specs, migration, model specs
parent 9c3cb4d3
......@@ -55,7 +55,7 @@ module AlertManagement
validates :severity, presence: true
validates :status, presence: true
validates :started_at, presence: true
validates :fingerprint, uniqueness: { scope: :project }, allow_blank: true
validates :fingerprint, uniqueness: { scope: :project }, allow_blank: true, unless: :resolved?
validate :hosts_length
enum severity: {
......
# frozen_string_literal: true
class AdjustUniqueIndexAlertManagementAlerts < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_alert_management_alerts_on_project_id_and_fingerprint'
RESOLVED_STATUS = AlertManagement::Alert::STATUSES[:resolved]
# rubocop:disable Migration/RemoveIndex
# rubocop:disable Migration/AddIndex
def up
remove_index :alert_management_alerts, name: INDEX_NAME
add_index(:alert_management_alerts, %w(project_id fingerprint), where: "status <> '#{RESOLVED_STATUS}'", name: INDEX_NAME, unique: true, using: :btree)
end
def down
remove_index :alert_management_alerts, name: INDEX_NAME
add_index(:alert_management_alerts, %w(project_id fingerprint), name: INDEX_NAME, unique: true, using: :btree)
end
# rubocop:enable Migration/RemoveIndex
# rubocop:enable Migration/AddIndex
end
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -94,6 +94,13 @@ RSpec.describe AlertManagement::Alert do
let(:project) { existing_alert.project }
it { is_expected.not_to be_valid }
context 'resolved status' do
# We are only validating uniqueness for non-resolved alerts
let(:new_alert) { build(:alert_management_alert, :resolved, fingerprint: fingerprint, project: project) }
it { is_expected.to be_valid }
end
end
context 'different project' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment