Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Level 2 · Technical ~2 min read

In one sentence: Data operations are dry-run by default, idempotent, and backed up so a change can be undone.

This chapter in plain terms

This chapter Guard — A test that enforces a project rule (e.g. “every module is in the AI_README”) and stops the commit when it’s broken. A rule without a guard is only a wish — a long session will break it in good faith. more in the glossary → one thing: that a data operation never surprises you with its result. Hence two iron rules.

Dry-run — A “dry” run — the script shows what it WOULD do but changes nothing. You see the effects before executing; a data change happens only after deliberate confirmation. more in the glossary → by default. Every script that changes data first only shows the plan — “I’ll change 4 rows, skip 0” — and actually writes only after your deliberate --execute. It’s a safety catch: you see the effect before it happens.

A copy before every change. Before you touch the database layout or live data, you take a Snapshot — A saved state of data from a specific moment — e.g. a database copy or a file of computed statistics. It speeds things up and keeps them safe, but is stale from the moment it’s taken — you need to know where fresh data comes from. more in the glossary → of it. Going back = restoring that copy (database changes go “forward only”, so the copy is the only way back).

The rest are practical traps. The trickiest: the same /tmp path means different things in different tools — Git Bash, Python — A popular, readable programming language — The Craft’s default for scripts, data and the back end. A proven default: lots of ready tools and libraries, easy to drive with AI. more in the glossary → and PowerShell expand it to three different folders. A script can “do nothing” because it reads an empty file in one place while your database sits in another. The cure: give full, unambiguous paths (Z:/data/app.db, not /tmp/app.db).

Example of Idempotency — A property of an operation you can run many times with the same result — no duplication. Key for scripts and events: a re-run doesn’t break data. Like an “ON” switch. more in the glossary →: a good data loader uses UPSERT — An “insert or update” write: if the record exists it’s updated, if not it’s added. It means a script run twice doesn’t create duplicates. more in the glossary →, so run twice it doesn’t duplicate records — just as safe the first time and the fifth.

Read more: database migrations — why · idempotence · a safe SQLite copy (.backup).

04 — Scripts and databases

Commandments IV and V: Dry-run — A “dry” run — the script shows what it WOULD do but changes nothing. You see the effects before executing; a data change happens only after deliberate confirmation. more in the glossary → is the default; the Backup — A copy of your data saved earlier, which you return to when something goes wrong. It’s the only way to undo a change to data — code comes back from git, data only from a backup. more in the glossary → is the Rollback — Reverting a change to the previous, working state — “Ctrl+Z” for a deployment. When a new version breaks production, a rollback restores the previous one in seconds instead of fixing in a panic. more in the glossary →.

Scripts

  1. Dry-run by default. A data-changing script prints the plan (what, how many rows, where); a deliberate --execute writes.
  2. Idempotency — A property of an operation you can run many times with the same result — no duplication. Key for scripts and events: a re-run doesn’t break data. Like an “ON” switch. more in the glossary →. Running it twice yields the same state (UPSERT — An “insert or update” write: if the record exists it’s updated, if not it’s added. It means a script run twice doesn’t create duplicates. more in the glossary → / UPSERT).
  3. Print what you did not do — truncation, sampling, skipped rows. Silence reads as “covered everything”.
  4. Catalog-mutating operations stay out of automatic Pipeline — A chain of processing steps run in order, e.g. fetch → clean → enrich → check. When each step runs on its own and repeats safely, a failure halfway doesn’t mean starting from zero. more in the glossary → (dedup, Merge — Combining the changes from one branch into another. A merge brings in every commit from the source branch — other people’s too — so first you check what exactly comes in. more in the glossary →): dry-run → review → --execute by hand.
  5. The environment is written in CLAUDE.md — interpreter, variables, venv. The agent doesn’t guess.
  6. Absolute paths when a value crosses tools. /tmp means one place to Git Bash, another to Python — A popular, readable programming language — The Craft’s default for scripts, data and the back end. A proven default: lots of ready tools and libraries, easy to drive with AI. more in the glossary → on Windows, a third to PowerShell — each tool then reads a different file. Pass fully-qualified paths; when a run “did nothing”, print os.path.abspath(p) / pwd -W and compare.

Databases and migrations

  1. Forward-only Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary →. No down-migrations; rolling back the schema = restoring the backup.
  2. Back up before every schema/data change on Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary →, with a timestamp and a retention window: sqlite3 data/app.db ".backup backups/pre-deploy-$(date +%F_%H%M%S).db"
  3. Snapshot — A saved state of data from a specific moment — e.g. a database copy or a file of computed statistics. It speeds things up and keeps them safe, but is stale from the moment it’s taken — you need to know where fresh data comes from. more in the glossary → with .backup / VACUUM INTO, never cp/scp of a live database — WAL — Write-Ahead Log: a database mode where changes go to a journal first, then to the data. Gives safety (recovery after a crash) and better read/write concurrency. more in the glossary → makes the copy inconsistent.
  4. Additive before destructive. ADD COLUMN is safe; DROP/RENAME waits for a later Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary →, once no running code reads the column.
  5. Check integrity after every data operation: integrity_check, foreign_key_check, row counts. Tell pre-existing noise (present before and after) from a regression (new violations).
  6. Rehearse a bulk or irreversible mutation on a fresh prod copy — a dry-run shows the plan, not the outcome. .backup prod → run on the copy → check counts, integrity and the tricky cases → then prod. The deploy-level sibling of this rule → 18.

Anti-patterns

  • 🚫 A mutating script without --dry-run.
  • 🚫 A migration deployed without a backup “because it’s additive”.
  • 🚫 Dropping a column running code still reads.
  • 🚫 cp app.db while the server runs.
  • 🚫 A catalog-mutating step wired into the automatic pipeline.
Chapter deep-dive 04Why these rules, examples and stories from projects — what the core deliberately leaves out.

The canonical doctrine is written in English.