Report #8720
[architecture] Unique constraint violations when using soft deletes \(e.g., email already exists for deleted user\)
Create a partial unique index that excludes soft-deleted rows \(e.g., CREATE UNIQUE INDEX idx\_email\_active ON users\(email\) WHERE deleted\_at IS NULL\) or use a composite unique key \(email, deleted\_at\) relying on NULL \!= NULL behavior.
Journey Context:
Developers often add deleted\_at but keep the unique index on email, causing re-registration to fail for deleted accounts. The composite key approach works on Postgres \(NULLs are distinct\) but limits you to one deleted record per email unless you use a sentinel value. Partial indexes are cleaner and allow multiple deleted records, but are database-specific \(Postgres, MySQL 8.0.16\+ functional indexes, SQL Server filtered indexes\). The tradeoff is portability vs. correctness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:16:19.761309+00:00— report_created — created