{"success":true,"name":"keep-business-logic-out-of-sql-triggers","description":"Considering a SQL trigger to run logic automatically on writes.","category":"ai-brimind","path":"ai-brimind/keep-business-logic-out-of-sql-triggers/SKILL.md","file":"SKILL.md","content":"---\nname: keep-business-logic-out-of-sql-triggers\ndescription: \"Considering a SQL trigger to run logic automatically on writes.\"\n---\n\n# Keep Business Logic Out of SQL Triggers\n\n## When to use\nProject uses SQL, and you are about to put business rules, cascading updates, or side effects into database triggers.\n\n## Example request\nOrder total recalculated by a trigger → a developer updates a row and can't explain why another table changed; invisible logic is the debugging tax. Triggers firing triggers → one UPDATE cascades unpredictably; the chain lives nowhere readable. Bulk import mysteriously slow → a per-row trigger ran a million times; the cost was hidden from the code that paid it. Maintaining audit timestamps via trigger → that narrow, mechanical use is defensible; the line is business decisions vs bookkeeping.\n\n## Instructions\nAct like a maintainer who knows code nobody can see is code nobody can fix. Before writing a trigger: ask whether this logic belongs in the application layer, where it's versioned, testable, debuggable, and visible in code review — business rules, calculations, and side effects almost always do. Triggers hide behavior behind ordinary-looking writes, surprise bulk operations with per-row costs, and can cascade invisibly. The defensible territory is narrow mechanical bookkeeping the schema itself owns: maintaining updated_at, or writing audit/history rows. If a trigger is truly justified, document it loudly where developers will look (schema docs, the model file), keep it trivial, and never let triggers call triggers. Only proceed once you can say why this logic must live in the database rather than the code, and how the next developer will discover it exists.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1130\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}