- Book: System Design Pocket Guide: Fundamentals
- The series: Pocket Guides for Developers — 8 short books on agents, RAG, prompts, observability, events, databases and system design — the whole series
- My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools
- Me: xgabriel.com | GitHub
Your coding agent adds an index and a check constraint in one migration file. The diff is a handful of correct SQL lines. The tests pass, because the test database holds a dozen rows.
GoCardless took about 15 seconds of unexpected API downtime from a planned migration it considered safe, because the tables being changed were empty and unused. A foreign key pointed at a busy table. A long read held that table, the migration queued behind the read, and every later query queued behind the migration.
None of that shows in a diff. Whether a statement hurts depends on the lock it takes and the traffic it meets. A linter can't see your traffic, but it knows which statements take which locks. Squawk is a linter for Postgres migrations. Make it the check that decides whether an agent's branch is finished.
Step 1: Run Squawk on a bad migration
Install it with npm install -g squawk-cli or pip install squawk-cli. The docs also list binaries and a Docker image. The latest release is v2.72.0, from November 8.
Here is the kind of file an agent writes when you ask for a lookup index and a sanity check on totals:
-- migrations/0042_orders_lookup.sql
BEGIN;
CREATE INDEX orders_customer_id_idx
ON orders (customer_id);
ALTER TABLE orders
ADD CONSTRAINT orders_total_positive
CHECK (total_cents > 0);
COMMIT;
Point Squawk at it:
squawk migrations/0042_orders_lookup.sql
Two rules matter on this file. Their messages, from the current source of the index rule and the constraint rule:
| Rule | Message | Help |
|---|---|---|
require-concurrent-index-creation |
during normal index creation, table updates are blocked, but reads are still allowed | use concurrently to avoid blocking writes |
constraint-missing-not-valid |
by default new constraints require a table scan and block writes to the table while that scan occurs | use not valid with a later validate constraint call |
Both match what Postgres documents. A plain CREATE INDEX locks the table against writes for the whole build. ADD CONSTRAINT scans the table to check every existing row, unless you add NOT VALID.

One statement holds the lock, and every write behind it waits.
Each warning names the rule, the line and the column, underlines the statement, and ends with help. This is the sample from Squawk's README, trimmed to fit, under the title warning[require-concurrent-index-creation]:
╭▸ example.sql:10:1
│
10 │ CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│
├ help: use `concurrently` to avoid blocking writes
In the full output, the same line is printed again with concurrently inserted. An agent reading that gets the diagnosis and the rewrite in one place. The exit code is the other half: any violation, syntax errors included, returns failure, and zero violations returns success. That makes it usable as a gate.
You will also see require-lock-timeout and require-statement-timeout, once per file. The docs for the lock rule and the statement rule say you can ignore each one when your connection already sets that timeout. If your connection or migration runner sets both, exclude the rules in the config file:
# .squawk.toml
excluded_rules = [
"require-lock-timeout",
"require-statement-timeout",
]
Step 2: Lint only what this branch changed
Running squawk 'migrations/*.sql' flags every old migration you can no longer change. You want the files this branch added or edited, and that includes files the agent hasn't committed. A check can run before the agent has committed anything, so comparing main...HEAD would miss the new file entirely.
#!/bin/sh
# scripts/lint-migrations.sh
set -eu
base=$(git merge-base main HEAD)
files=$( {
git diff --name-only --diff-filter=ACMR "$base" \
-- 'migrations/*.sql'
git ls-files --others --exclude-standard \
-- 'migrations/*.sql'
} | sort -u )
if [ -z "$files" ]; then
echo "no new or changed migrations"
exit 0
fi
if grep -n 'squawk-ignore' $files; then
echo "squawk-ignore needs human review" >&2
exit 1
fi
squawk $files
git diff <commit> compares your working tree with that commit, so edits count whether or not they are staged. It ignores untracked files, so git ls-files --others --exclude-standard picks those up. Change main and the path if yours differ. The script splits on whitespace, so it assumes no spaces in migration names.
The grep guards against something an agent can do. Squawk honors -- squawk-ignore rule-name on a statement and -- squawk-ignore-file on a whole file. An agent told to make a check green can reach for that comment, so this check refuses it and leaves the decision to a person.
Step 3: Make it the check that decides done
The rest of this post uses Hermes IDE, which I build, so weigh it with that in mind. Its README says your own checks can decide when a task is done, and sh scripts/lint-migrations.sh is the check to give it. The README points to docs/worktree-recipes.md for worktree setup per repository, so read that page for how to set it up in yours.
Commit the script and .squawk.toml, so each new worktree has them. The script needs sh, so this fits macOS and Linux. If the check can't find squawk, add squawk-cli as a dev dependency and call npx squawk on the script's last line.
Next, tell the agent about the gate, so it sees the warnings while it is still working. Put this in CLAUDE.md for Claude Code or AGENTS.md for Codex:
## Database migrations
- SQL goes under migrations/. Assume a live Postgres table.
- After writing one, run: sh scripts/lint-migrations.sh
- Fix what it reports. Never add squawk-ignore.
- Never edit that script or .squawk.toml.
The instruction alone won't hold: Anthropic's docs say Claude treats these files as context, not enforced configuration. The check doesn't depend on the agent reading that file, though the agent can still edit the script, which is why Step 4 reviews the gate too.
Press ⌘N (Ctrl+Shift+N on Windows and Linux) and describe the task. It starts in a real terminal on its own hermes/ branch and worktree, with the task as its first prompt.

The ⌘N New task sheet: the task, the agent, a new hermes/ worktree, and the command Hermes will run.
When the agent follows that instruction, the warnings land in its own session, and it can rewrite the migration before you open the diff. I haven't run this exact loop against a live agent, so try it on a throwaway migration first.
Step 4: Read the rewrite
A correct rewrite is three files. The index goes first, alone and outside any transaction, because Postgres doesn't allow CREATE INDEX CONCURRENTLY inside a transaction block:
-- migrations/0042_orders_customer_idx.sql
CREATE INDEX CONCURRENTLY IF NOT EXISTS
orders_customer_id_idx ON orders (customer_id);
The IF NOT EXISTS and the explicit name are for Squawk's prefer-robust-stmts rule, which expects a guard on statements that run outside a transaction. Then the constraint, added without the scan:
-- migrations/0043_orders_total_check.sql
BEGIN;
ALTER TABLE orders
ADD CONSTRAINT orders_total_positive
CHECK (total_cents > 0) NOT VALID;
COMMIT;
The validation goes in a separate migration. Squawk's rule calls for that second step, and its source flags NOT VALID plus VALIDATE in one transaction. VALIDATE CONSTRAINT takes only SHARE UPDATE EXCLUSIVE, so writes keep flowing during the scan:
-- migrations/0044_orders_total_validate.sql
BEGIN;
ALTER TABLE orders
VALIDATE CONSTRAINT orders_total_positive;
COMMIT;
Both ALTERs stay in a BEGIN/COMMIT because prefer-robust-stmts flags them outside a transaction and skips them inside one. If your migration tool already wraps each file in a transaction, set assume_in_transaction = true in .squawk.toml and delete the BEGIN and COMMIT lines from 0043 and 0044, because Squawk's transaction-nesting rule flags both when the tool owns the transaction. With that setting, Squawk flags a concurrent index only when its file holds other statements, so keep it alone in its file and use your tool's non-transactional option. The rule's docs show how for Alembic, and note that golang-migrate handles a file holding only the CREATE INDEX.
Press ⌘G (Ctrl+Shift+G) to open the Review Desk. When the first attempt and the rewrite came in different turns, the by-turn view lets you read them apart. Look for edits to scripts/lint-migrations.sh and .squawk.toml too, since the agent shouldn't be touching the gate.

The Review Desk by turn on a demo task: two turns, one diff, and a commit message drafted from them.
What a green check doesn't prove
Squawk's own guide says that passing the lint doesn't make a migration safe to run. Even the NOT VALID add takes an ACCESS EXCLUSIVE lock for a moment, and if a long query already holds the table, your ALTER waits and everything behind it queues. That is what happened at GoCardless. The guide's answer is a short lock_timeout (about 1 second) with retries, plus a statement_timeout (about 5 seconds, tuned up for slow work like a concurrent index build on a large table). You can set both at run time with PGOPTIONS='-c lock_timeout=1s -c statement_timeout=5s' in front of your migration command, raising the statement timeout for the concurrent index.
CONCURRENTLY has its own cost. Postgres warns it does more total work and takes significantly longer, and a failed build leaves an INVALID index behind that you have to drop and retry. Because this migration uses IF NOT EXISTS, a rerun reports success even when the existing index is invalid. After a failure, check pg_index (\d orders also marks it INVALID) and drop the index before you rerun.
Squawk lints SQL. If your migrations are in Python or an ORM's format, render them to SQL first and lint that. If you'd rather gate on pull requests, the docs include a GitHub Actions workflow using sbdchd/squawk-action.
Which Postgres statement has burned you the worst under load? Tell me in the comments.
If this was useful
An index that blocks writes is an availability problem long before it is a SQL problem. System Design Pocket Guide: Fundamentals is my short read on the building blocks scalable systems are made of, for when you want to reason about what a write path has to survive. It's one of 8 short books in the Pocket Guides series, covering agents, RAG, prompts, observability, events, databases and system design.
Hermes IDE is free, source-available under BSL 1.1, and runs on macOS, Windows and Linux. It's on GitHub, and it isn't affiliated with Nous Research, Anthropic, OpenAI or any agent vendor.

Top comments (1)
The grep guard against -- squawk-ignore is the detail most write-ups would leave out, and it's the one that matters most once an agent is in the loop. A linter the agent can silence with a comment isn't a gate, it's a suggestion — and an agent under pressure to make a check green will reach for exactly that comment. Refusing the branch on it is the right call.
The trap I'd add to the checklist is the one you flagged at the end: IF NOT EXISTS reporting success over an INVALID index. That turns a failed build into a silent no-op on rerun, which is worse than a loud failure. One question: do you run the pg_index INVALID check as part of the same gate, or is that a separate post-deploy verification step? If the gate only runs Squawk, the invalid-index case slips through both — the migration "passes" and the index is still unusable.