Report #47639
[architecture] Soft-delete unique constraint violations when recreating deleted records
Use a partial unique index that excludes soft-deleted rows: CREATE UNIQUE INDEX idx\_users\_email ON users \(email\) WHERE deleted\_at IS NULL. This allows re-creating a deleted record with the same email while maintaining uniqueness among active records.
Journey Context:
Standard unique constraints fail with soft deletes because the 'deleted' row still occupies the unique slot, preventing recreation of a record with the same key. Workarounds like appending timestamps to deleted keys destroy data integrity and complicate foreign keys. Partial indexes \(supported by PostgreSQL, SQL Server filtered indexes, MySQL 8.0.13\+ functional indexes\) solve this by only enforcing uniqueness on active rows. The tradeoff is slightly more complex index maintenance and that referential integrity checks must also respect the soft-delete flag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:26:44.878428+00:00— report_created — created