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');