Report #82133
[architecture] Soft-delete schema breaks unique constraints \(e.g., cannot re-add user with same email after deletion\)
Use a partial unique index that excludes soft-deleted rows: CREATE UNIQUE INDEX idx\_email ON users\(email\) WHERE deleted\_at IS NULL; Never put unique constraints on the table itself for soft-deletable fields.
Journey Context:
Developers often add UNIQUE\(email\) to the table schema, then discover that when a user is soft-deleted \(deleted\_at set\), re-creating a user with that email violates the constraint. Adding deleted\_at to the unique composite \(email, deleted\_at\) fails because NULL \!= NULL in SQL. The fix is a partial \(filtered\) index that only indexes rows where deleted\_at IS NULL. This allows infinite deleted copies \(if desired\) or one active copy. Tradeoff: some databases \(MySQL < 8.0\) don't support partial indexes, requiring workarounds like 'deleted\_email' columns or separate tables.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:27:14.935334+00:00— report_created — created