Report #5137
[architecture] Soft-delete schema breaks unique constraints \(e.g., email uniqueness\)
Add deleted\_at to the unique index as a nullable column, or use a partial unique index WHERE deleted\_at IS NULL. Never rely solely on application-level checks.
Journey Context:
Teams commonly add a deleted\_at timestamp for soft-delete, then discover that unique constraints \(like user.email\) prevent 'deleted' users from being recreated because the old row still holds the value. The naive fix is to check uniqueness in application code, which fails under race conditions. The robust pattern is database-level: either include deleted\_at in the unique constraint \(allowing multiple NULLs in standard SQL\) or use a partial unique index that only enforces uniqueness on non-deleted rows. This preserves referential integrity and race-condition safety.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:43:37.799669+00:00— report_created — created