Report #93248
[architecture] How to enforce unique constraints with soft-deleted records in SQL databases
Use partial unique indexes that exclude soft-deleted rows: CREATE UNIQUE INDEX idx\_unique\_active ON table \(column\) WHERE deleted\_at IS NULL
Journey Context:
Standard unique constraints fail because deleted rows still occupy the unique slot. Common workarounds like appending deleted\_at to unique constraint \(a,b,deleted\_at\) break when multiple deleted versions exist \(NULL \!= NULL\). Partial indexes are the cleanest solution but only PostgreSQL and SQL Server support them fully; MySQL 8.0.13\+ has functional indexes but not partial, requiring soft-delete logic in application or trigger-based workarounds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:06:05.181919+00:00— report_created — created