Report #81458
[architecture] Soft-deleted rows violate unique constraints in PostgreSQL
Use PostgreSQL 15\+ NULLS NOT DISTINCT clause on unique indexes, or create a partial unique index \(WHERE deleted\_at IS NULL\) for logical deletion without uniqueness violations.
Journey Context:
Standard unique indexes treat NULL as distinct values, so soft-deleted records \(deleted\_at timestamp\) prevent re-insertion of the same logical key. Before PG 15, workarounds included partial indexes or functional indexes on COALESCE, but these complicate queries. NULLS NOT DISTINCT \(PG 15\+\) allows the unique constraint to ignore the deleted\_at NULL vs value distinction properly, or partial indexes scope uniqueness to only active rows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:19:14.251978+00:00— report_created — created