sqitchcraft

Instructions for agents

Everything on this site is a set of habits a careful engineer picks up over time. A coding agent has none of them, but it follows written rules well. This page is the AGENTS.md we recommend, so an agent can make schema changes on its own and tell you clearly what it did and what it left for you to decide.

Two files: AGENTS.md, the instructions, and check-database, a script the instructions tell the agent to run before it finishes.

Why agents need it written down

Asked to "add a currency to invoices", an agent with no instructions does what most of the internet does: writes 0042_add_currency.sql with an alter table, maybe edits the table's file too, and calls it done. Every habit on this site is invisible from the code alone:

The file writes those down, in the order an agent needs them: where things are, which workflow fits the task, the rules, how to check, when to stop, and what to report.

Install it

  1. Add the instructions. Save AGENTS.md at the root of your repository. Codex and most other agents read AGENTS.md on their own. If you already have one, paste it in as a section. For Claude Code, add a line to CLAUDE.md that imports it:
    @AGENTS.md
  2. Add the check. Save check-database as scripts/check-database and make it executable. Run it yourself once to see it pass.
  3. Fill in the details. Replace the guide URL placeholder, and change master if your main branch has another name. If your services are not written in Haskell, delete the hasql-check line.
  4. Give the agent the tools. sqitch, sqiff, sqint, create-migration, psql and a PostgreSQL it may create scratch databases on, with PG* variables pointing at it. With Nix:
    nix shell nixpkgs#sqitchPg nixpkgs#postgresql_18 \
      github:kronor-io/sqiff github:kronor-io/sqint github:kronor-io/sqitch-with-templates

What the file says

SectionWhat it gives the agent
Where things areThe layout, and the instruction to read an object's definition instead of reconstructing it from migrations.
Choose the workflowA table from task to command: create an object, change a table, change a function or view, the multi-release recipes. Where a rule goes: constraints and types first, then views, functions and statecharts. Commands are given with every flag, because create-migration prompts when one is missing and sqitch opens an editor without -n.
Model a processWhen rows go through a process, a statechart, never a status column, enum or flags. The signs that a task is a process, how to change a chart, and that late and duplicate events are left to the chart rather than turned into errors.
Code that talks to the databaseThe runtime rules from practices: every write at SERIALIZABLE through one retrying function, no calls to other systems while a transaction is open, idempotency keys inserted before they are read, and queues claimed with skip locked.
RulesThe nevers and alwayses from the layout, functions and shipping safely, stated without exceptions.
Merging and rebasingThe regenerate-don't-merge procedure from git and review, and why a stale snapshot matters.
Check before you finishOne command, and what to do with sqint's findings: fix BLOCKs, never write a lint:ignore itself.
Stop and askThe judgement calls: rewrites, data loss, renames, backfills of unknown size, conflicts in lines already on the main branch.
ReportWhat changed, every hazard and what was done about it, which release each part belongs to, and every check with its result.

Two choices are deliberate. The agent may not suppress a lint finding: a lint:ignore records a human's decision, and an agent writing one defeats the point. And it reports the hazards it accepted instead of silently accepting them, so the reviewer reads them first.

The check script

An agent is only as careful as the check it runs at the end. scripts/check-database puts the important checks behind one command, so the instructions can say "run this" rather than describe a procedure:

$ scripts/check-database
== sqint: deploy scripts changed since master
== pgfmt: SQL files changed since master
== the plan only grows
== snapshots are not edited
== fresh database: deploy the whole plan
Deploying changes to db:pg:check_database_scratch
  + base_schemas ................................................. ok
  …
  + migrations/2026/11/2026-11-25-105014-add-column-billing.invoice.note .. ok
== revert this branch's 2 changes and deploy them again
  - migrations/2026/11/2026-11-25-105014-add-column-billing.invoice.note .. ok
  + migrations/2026/11/2026-11-25-105014-add-column-billing.invoice.note .. ok
== database checks passed

It reverts the branch's changes by counting them back from the end of the plan (sqitch rebase --onto @HEAD^2), not by name, because a reworked change's name is ambiguous. It leaves out sqint's dynamic pass, which needs the base branch deployed first; CI runs that. Run it in CI too, so the agent's check and the merge check are the same.

Guardrails outside the file

Instructions are followed most of the time. For the things that must never happen, do not rely on them alone.

The file

AGENTS.md (download)

Loading agents/AGENTS.md…