Report #57988
[architecture] Using boolean deleted flags in SQL schemas with unique constraints
Use a nullable deleted\_at timestamp and enforce uniqueness via partial indexes \(PostgreSQL\) or filtered indexes \(SQL Server\) that only index rows where deleted\_at IS NULL
Journey Context:
Boolean flags break unique constraints because SQL treats NULL \!= NULL; you cannot have unique\(email\) if a soft-deleted row with that email exists. Timestamps allow partial indexes \(WHERE deleted\_at IS NULL\) which enforce uniqueness only among active rows while preserving audit trail of deletion time. Common mistake: trying to use boolean flags then wondering why UNIQUE constraints fail when re-inserting 'deleted' data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:49:19.488693+00:00— report_created — created