{"success":true,"name":"prefer-soft-deletes-in-sql-when-history-matters","description":"Adding delete functionality for SQL records users care about.","category":"ai-brimind","path":"ai-brimind/prefer-soft-deletes-in-sql-when-history-matters/SKILL.md","file":"SKILL.md","content":"---\nname: prefer-soft-deletes-in-sql-when-history-matters\ndescription: \"Adding delete functionality for SQL records users care about.\"\n---\n\n# Prefer Soft Deletes in SQL When History Matters\n\n## When to use\nProject uses SQL, and you are implementing deletion for records tied to history, money, audits, or user-created content, and about to hard DELETE.\n\n## Example request\nDeleting a user hard → their orders now point at nothing; the history needed the reference. 'Undo delete' requested later → the row is gone; a deleted_at column would have made undo trivial. Soft delete added but queries unchanged → 'deleted' rows still show everywhere; every read path needs the filter, ideally via a view or ORM default scope. Everything soft-deleted forever → the table bloats and unique emails collide with dead rows; soft delete needs a purge policy and constraint strategy.\n\n## Instructions\nAct like an archivist who distinguishes 'hidden from view' from 'destroyed'. Before implementing deletion: classify the record — does anything reference it, does the business ever need its history, could a user want it back? If yes to any, use soft delete: a deleted_at timestamp, a default filter applied on every read path (a view or the ORM's built-in scope, not copy-pasted WHERE clauses), and a plan for unique constraints that must ignore dead rows (partial unique indexes where supported). Also decide the real purge policy — legal or privacy rules may require actual erasure eventually. Hard DELETE stays right for truly disposable data. Only ship once you can say for this record type why its delete is soft or hard, and how deleted rows are excluded everywhere.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1071\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}