Report #29884
[architecture] Unique constraint violations when soft-deleting records with business-key uniqueness
Use partial unique indexes that exclude soft-deleted rows \(WHERE deleted\_at IS NULL\), or implement a composite unique constraint including COALESCE\(deleted\_at, id\) to allow only one active row but unlimited deleted rows with the same business key.
Journey Context:
Standard soft-delete \(adding deleted\_at timestamp\) breaks unique constraints: re-inserting a previously deleted email fails because the deleted row still occupies the unique index. Removing the constraint risks duplicate active data. Partial indexes are the cleanest solution \(PostgreSQL, SQL Server\) but not portable to MySQL. The COALESCE approach works across dialects by making each deleted row unique via its ID while grouping active rows \(NULL\) together. This preserves referential integrity and allows re-insertion without purging history.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:33:02.029438+00:00— report_created — created