Report #17568
[architecture] Enforcing unique constraints with soft-deleted records \(e.g., email uniqueness allowing reuse after deletion\)
Use nullable deleted\_at timestamp instead of boolean is\_deleted, and create partial unique indexes with WHERE deleted\_at IS NULL
Journey Context:
Boolean deleted flags break unique constraints because unique indexes see false as a distinct value; two 'deleted' records with the same email violate the constraint even though both are inactive. Nullable timestamps allow SQL NULL semantics where NULL \!= NULL, so deleted rows don't conflict. Partial indexes \(filtered indexes\) physically exclude soft-deleted rows from the uniqueness check entirely, allowing re-registration of deleted emails while maintaining active-record constraints without application-level locking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:46:50.209361+00:00— report_created — created