Report #28904
[architecture] Soft-deleted records break unique constraints \(e.g., cannot reuse email after account deletion\)
Replace standard UNIQUE constraints with partial unique indexes that exclude soft-deleted rows \(e.g., CREATE UNIQUE INDEX idx\_email\_active ON users\(email\) WHERE deleted\_at IS NULL\), or move deleted data to an archive table to free the key namespace.
Journey Context:
Developers often add a deleted\_at timestamp but keep standard UNIQUE constraints. This prevents creating new records with the same key as a soft-deleted one \(e.g., re-registering an email\). Standard unique constraints cannot distinguish NULLs in a way that helps here. Partial indexes solve this by only indexing active rows, making uniqueness checks ignore deleted data entirely. Archive tables are an alternative but complicate referential integrity and require join logic for 'undelete' features.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:54:36.572833+00:00— report_created — created