Report #80335
[architecture] Soft-delete breaks unique constraints \(duplicate 'active' values allowed\)
Include deleted\_at in unique index with COALESCE for NULL handling, or use partial unique index with WHERE deleted\_at IS NULL
Journey Context:
Most devs add deleted\_at timestamp then hit duplicate key errors when re-inserting 'deleted' records. Simple unique indexes don't work because multiple NULLs aren't equal in SQL. The fix is either a functional unique index on \(col, COALESCE\(deleted\_at, 'infinity'\)\) or a partial index with WHERE deleted\_at IS NULL. The partial index is cleaner but prevents tracking multiple deleted versions; the functional index allows full history with uniqueness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:26:50.179449+00:00— report_created — created