Report #96465
[architecture] Unique constraint violations when soft-deleting records with business-natural keys \(e.g., user email\)
Replace table-level unique constraints with partial unique indexes \(WHERE deleted\_at IS NULL\) to enforce uniqueness only among active records while allowing historical duplicates
Journey Context:
Many teams implement soft deletes then discover their unique email/username constraints prevent "reclaiming" a deleted record or creating a new one with the same key. Common wrong approaches include: application-level validation \(race conditions\), triggers \(complexity\), or cascading hard deletes \(data loss\). Partial indexes are the declarative SQL solution that enforces integrity at the database level without application code and without checking deleted rows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:29:56.135466+00:00— report_created — created