Report #68006
[architecture] Soft-delete breaks unique constraints \(e.g., email\) when re-adding deleted records
Use partial unique indexes that exclude soft-deleted rows: CREATE UNIQUE INDEX idx\_unique\_email ON users\(email\) WHERE deleted\_at IS NULL. Do not rely on application-level checks or composite indexes with NULL.
Journey Context:
Teams often add a deleted\_at timestamp but keep a unique constraint on email/username. This prevents recreating an account with a previously deleted email because the old row still exists. The 'fix' of using a composite unique index on \(email, deleted\_at\) fails because NULL \!= NULL in SQL, allowing duplicate emails if deleted\_at is NULL for multiple rows. The correct pattern is a partial \(filtered\) index that only enforces uniqueness among non-deleted rows. This requires database support \(PostgreSQL, SQL Server\) or generated columns in MySQL 8.0\+.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:37:54.814844+00:00— report_created — created