Report #43169
[architecture] Soft-delete breaks foreign key constraints and unique indexes
Use deleted\_at timestamp with partial unique indexes \(WHERE deleted\_at IS NULL\) or move deleted rows to an archive table; never use boolean is\_deleted flags on tables with foreign key relationships.
Journey Context:
Boolean soft-delete flags break referential integrity because the parent row still exists, preventing cascade deletes and blocking foreign keys from working naturally. They also break unique constraints \(e.g., email must be unique only for active users\). The solutions are: \(1\) Partial indexes in PostgreSQL \(CREATE UNIQUE INDEX ... WHERE deleted\_at IS NULL\), which enforces uniqueness only among live rows, or \(2\) A separate archive table that preserves the full row with metadata, allowing the main table to hard-delete and maintain clean FK relationships. Tradeoff: partial indexes are database-specific; archive tables require application logic to query across both tables when needed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:55:57.950738+00:00— report_created — created