Report #4894
[architecture] Unique constraint violations when re-creating soft-deleted records
Use a partial unique index \(WHERE deleted\_at IS NULL\) instead of a table-level unique constraint to enforce uniqueness only among active rows while allowing deleted rows to retain historical values.
Journey Context:
Standard unique constraints cannot distinguish between NULL values in soft-delete columns, causing 'duplicate key' errors when a user deletes an account and tries to re-register with the same email. Partial indexes solve this by only indexing non-deleted rows. Alternative approaches like using a compound unique key on \(email, COALESCE\(deleted\_at, '1970-01-01'\)\) pollute the index with tombstones and complicate queries. The partial index approach maintains referential integrity for active data while correctly allowing soft-deleted historical records to remain for audit/compliance without blocking new inserts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:15:45.649890+00:00— report_created — created