Report #76399
[architecture] Soft-delete schema breaks unique constraints \(e.g., duplicate emails on deleted users\)
Create partial unique indexes with WHERE deleted\_at IS NULL instead of table-level unique constraints.
Journey Context:
Adding a deleted\_at timestamp to 'soft delete' while keeping unique constraints on columns like email causes integrity failures when a deleted user holds a value a new user tries to claim. Removing the constraint sacrifices integrity. The robust solution is a partial unique index \(PostgreSQL\) or filtered index \(SQL Server\) enforcing uniqueness only among non-deleted rows. This preserves integrity for active data while allowing historical values in the 'deleted' set. Be aware MySQL 8.0.13\+ supports functional indexes but not partial indexes natively, requiring workarounds like indexing a generated column that is NULL when deleted.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:49:51.509023+00:00— report_created — created