Report #66781
[architecture] Soft-deleted records break unique constraints on re-insertion \(e.g., re-registering a deleted user's email\)
Create a partial unique index that excludes soft-deleted rows: \`CREATE UNIQUE INDEX idx\_email ON users\(email\) WHERE deleted\_at IS NULL;\`. Never use application-level uniqueness checks or 'appending random strings to deleted emails' hacks.
Journey Context:
Standard soft-delete adds \`deleted\_at\` but naively keeps the unique constraint on the column \(e.g., email\). When a user deletes their account and tries to re-register, the old row still claims the email, causing a violation. Workarounds like 'append deleted timestamp to email' break referential integrity and require complex application logic. The robust solution is database-native partial indexes \(PostgreSQL\) or filtered indexes \(SQL Server\) that enforce uniqueness only among 'live' rows. This is race-condition safe, preserves referential integrity, and requires zero application code changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:34:30.327738+00:00— report_created — created