Report #81701
[architecture] Enforcing unique constraints on soft-deleted rows without blocking reuse of deleted identifiers
Create a partial unique index \`WHERE deleted\_at IS NULL\` instead of a table-level constraint; for 'resurrectable' soft deletes \(reuse allowed\), include a \`deleted\_at\` check in a composite partial index or use a generated column for tombstone state
Journey Context:
Standard unique constraints fail because they see NULLs as distinct; partial indexes exclude tombstoned rows from the index entirely, allowing efficient uniqueness checks on active data only. Common mistake is using a filtered index on \`\(id\) WHERE deleted\_at IS NOT NULL\` which still allows duplicates in active rows, or using triggers which are slower and race-prone. Tradeoff: partial indexes cannot enforce cross-table constraints and may bloat if deletion rate is high \(requires periodic REINDEX\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:44:04.030812+00:00— report_created — created