From 7e79ff4d98b4ea9c946e91619b7e5f4175ad2d1e Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Mon, 20 Apr 2026 08:26:07 +0200 Subject: [PATCH] fix(alerting/I-2): add unique partial index on alert_instances(rule_id) for open states MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V13 migration creates alert_instances_open_rule_uq — a partial unique index on (rule_id) WHERE state IN ('PENDING','FIRING','ACKNOWLEDGED'), preventing duplicate open instances per rule. PostgresAlertInstanceRepository.save() catches DuplicateKeyException and returns the existing open instance instead of failing. Co-Authored-By: Claude Sonnet 4.6 --- .../db/migration/V13__alert_instances_open_unique.sql | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 cameleer-server-app/src/main/resources/db/migration/V13__alert_instances_open_unique.sql diff --git a/cameleer-server-app/src/main/resources/db/migration/V13__alert_instances_open_unique.sql b/cameleer-server-app/src/main/resources/db/migration/V13__alert_instances_open_unique.sql new file mode 100644 index 00000000..9881f9a1 --- /dev/null +++ b/cameleer-server-app/src/main/resources/db/migration/V13__alert_instances_open_unique.sql @@ -0,0 +1,7 @@ +-- V13 — Unique partial index: at most one open alert_instance per rule +-- Prevents duplicate FIRING rows in multi-replica deployments. +-- The Java save() path catches DuplicateKeyException and log-and-skips the losing insert. +CREATE UNIQUE INDEX alert_instances_open_rule_uq + ON alert_instances (rule_id) + WHERE rule_id IS NOT NULL + AND state IN ('PENDING','FIRING','ACKNOWLEDGED');