Report #12907
[architecture] Soft-delete schema breaks unique constraints on email/username
Use partial unique indexes that exclude soft-deleted rows: CREATE UNIQUE INDEX idx\_email ON users\(email\) WHERE deleted\_at IS NULL; alternatively use a separate tombstone table for deleted data.
Journey Context:
Standard soft-delete \(deleted\_at timestamp\) collides with unique constraints because the row still exists. Common mistake is removing the unique constraint entirely, losing data integrity. Partial indexes \(PostgreSQL\) or filtered indexes \(SQL Server\) solve this by only enforcing uniqueness on active rows. MySQL 8.0.16\+ supports functional indexes but not partial indexes directly; workaround is a generated column that is NULL when deleted and indexed. Tradeoff: queries must include 'WHERE deleted\_at IS NULL' to use the index effectively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T17:17:04.397064+00:00— report_created — created