Report #74674
[architecture] Soft-delete schema breaks foreign key referential integrity
Use deferred constraint checking \(PostgreSQL: \`SET CONSTRAINTS ALL DEFERRED\`\) to allow soft-deleting parents while children exist within the same transaction, or migrate to partitioned tables \(active/archived\) instead of flag-based soft deletes to preserve referential integrity without complex deferred logic.
Journey Context:
Developers routinely add \`deleted\_at\` timestamps without realizing that soft-deleting a parent row while children exist violates foreign key constraints immediately. Immediate constraint checking prevents the delete, while cascading deletes destroy the audit trail. Deferred constraints delay the check until transaction commit, allowing you to soft-delete children and parents atomically. However, ORMs often don't support deferred constraints well, and they don't work across distributed transactions. The partitioned approach \(moving rows to an 'archived' partition\) maintains referential integrity naturally because the row actually moves, not just flagged, though this complicates queries that must span both partitions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:56:15.661505+00:00— report_created — created