Report #5363
[architecture] Enforcing unique constraints only on non-deleted rows in soft-delete schemas
Create partial unique indexes with WHERE deleted\_at IS NULL clause. Do not rely on filtered unique constraints or application-level checks for uniqueness enforcement.
Journey Context:
Standard unique indexes reject duplicates even if rows are soft-deleted, causing 'ghost' unique violations when re-creating previously deleted records. Application-level uniqueness checks race between SELECT and INSERT. Partial indexes \(supported by PostgreSQL, SQL Server filtered indexes, MySQL 8.0.13\+ functional indexes with WHERE\) enforce constraint only on live data. Tradeoff: Some DBs don't use partial indexes for certain query types; requires understanding of index predicates; migration requires rebuilding index concurrently to avoid locks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:08:57.941894+00:00— report_created — created