Report #75350
[architecture] Implementing soft-delete without breaking unique constraints
Use partial unique indexes \(WHERE deleted\_at IS NULL\) instead of adding deleted\_at to composite constraints or relying on application-level checks
Journey Context:
The common mistake is creating a unique constraint on \(email, deleted\_at\) to allow 'deleted' duplicates, but this permits multiple active rows with the same email if deleted\_at timestamps differ, or requires nullable deleted\_at with a default epoch value which is messy. Application-level uniqueness checks race and fail under concurrency. Partial indexes enforce uniqueness only on live rows at the database level, are race-safe, and query efficiently. Tradeoff: MySQL <8.0.13 lacks functional/partial index support natively \(MariaDB and PostgreSQL support this well\), requiring generated columns as a workaround.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:04:32.647947+00:00— report_created — created