Report #61064
[architecture] Soft-delete schema breaks unique constraints on reused values \(e.g., email, slug\)
Replace standard UNIQUE constraints with partial unique indexes that exclude soft-deleted rows \(e.g., CREATE UNIQUE INDEX idx\_live\_email ON users\(email\) WHERE deleted\_at IS NULL\). This allows deleted values to be reclaimed by new records without violating database constraints.
Journey Context:
Standard unique constraints see soft-deleted rows, blocking you from reusing an email or slug even after the original owner is deleted. Adding deleted\_at to the constraint \(email, deleted\_at\) fails because timestamps make every row unique, preventing any true duplicate detection. Partial indexes are the only performant solution, but they require database support \(PostgreSQL, SQL Server filtered indexes, MySQL 8.0.13\+ functional key parts\). Alternatives like 'deleted' boolean flags with partial indexes work, but nullable timestamps are more standard. This pattern must be chosen on day one; retrofitting it requires rebuilding indexes and handling collisions in existing soft-deleted data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:58:56.216314+00:00— report_created — created