Report #10662
[architecture] Soft-delete unique constraint violations on re-insert
Use partial unique indexes that exclude soft-deleted rows: CREATE UNIQUE INDEX idx\_active ON users\(email\) WHERE deleted\_at IS NULL \(PostgreSQL\) or CREATE UNIQUE INDEX idx\_active ON users\(email\) WHERE deleted\_at IS NULL \(SQL Server filtered index\). Never rely on application-level checks.
Journey Context:
Standard unique indexes fail with soft deletes because the deleted record still occupies the unique slot, preventing re-creation of that email/username. Devs often try 'IS NULL' unique indexes on nullable columns, but that only allows one NULL. Partial/filtered indexes solve this by creating the constraint only on the subset where deleted\_at IS NULL, effectively making deleted records invisible to the uniqueness check. Alternatives like 'deleted boolean \+ unique index on \(col, deleted\)' fail because you can only have one deleted=false and one deleted=true per value.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:18:08.602146+00:00— report_created — created