{"success":true,"name":"give-every-data-script-a-dry-run-mode-print-what-would-chang","description":"Writing a script that will modify database records when executed","category":"ai-brimind","path":"ai-brimind/give-every-data-script-a-dry-run-mode-print-what-would-chang/SKILL.md","file":"SKILL.md","content":"---\nname: give-every-data-script-a-dry-run-mode-print-what-would-chang\ndescription: \"Writing a script that will modify database records when executed\"\n---\n\n# Give Every Data Script a Dry-Run Mode: Print What Would Change, Write Nothing\n\n## When to use\nYou are writing (or about to run) a script whose job is to modify database data, and executing it immediately performs the writes — there is no mode where it only reports what it WOULD do.\n\n## Example request\nA script is run 'to see what happens' → seeing what happens IS the write; with a dry-run flag, seeing and doing are two different commands. A dry-run prints 'would update 4,812 rows' when ~300 were expected → the filter bug is caught by reading a line of output, at the cost of zero rows. The dry-run lists sample rows it would touch → three of them clearly should not be there; the eyes catch what the WHERE clause missed. The script defaults to writing and dry-run needs a flag → one forgotten flag equals an accident; safe must be the default, danger must be the thing you type on purpose.\n\n## Instructions\nAct as an engineer who never builds a button that fires immediately — every dangerous action first shows a preview, and firing requires a deliberate second step. When writing any script that modifies database data, build it like this: (1) Structure the script in two halves: first SELECT/find everything the change would touch, then apply the change to that set. This split is what makes a preview possible at all. (2) Add a dry-run mode, and make it the DEFAULT: running the script with no arguments only prints — the count of records it would modify, a small sample of them (a few IDs plus current value → new value), and zero writes. Actually writing requires an explicit, loud flag like --execute or --apply; safety by default, danger by opt-in, because a forgotten flag must fall on the safe side. (3) Run the dry-run and read it like a reviewer: does the count match the number you predicted before running? Do the sample rows belong in this change? Do the 'new value' previews look right? Any surprise means the script is wrong — fix and dry-run again; the whole point is that this loop costs nothing. (4) Only when the dry-run output matches your prediction exactly do you run with the execute flag — and per your other disciplines: fresh backup taken first, its path and restore command written down, and batching if the count is large. (5) After executing, print what was ACTUALLY changed (count and sample) and compare it to the dry-run's promise — the two must match; a difference means something moved under you and needs investigating before anything else runs. Only call the script trustworthy when the pattern holds: preview said N, execute did N, and the preview never touched a single row.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #615\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}