Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ jobs:
# Migrations run before the rollout, so the release still serving must work with the new schema: a new migration
# mustn't drop, rename or retype what main's code reads (4 Dec 2026: a dropped column failed requests for ~20 s).
- run: python3 -m unittest scripts/ci/test_migration_safety.py
- uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0
with:
install_args: github:sbdchd/squawk
# Migrations run in file-name order and are recorded by name, so one already on main is never renamed or edited,
# and a new one sorts after all of main's (two branches that each add one: the second to merge takes a later
# timestamp). With no base it can reach (a new branch, a force-push), only the names are checked.
Expand All @@ -167,6 +170,8 @@ jobs:
else
scripts/ci/check_migrations.sh "$BASE"
python3 scripts/ci/migration_safety.py "$BASE"
# Postgres migration lint on the new ones' SQL (.squawk.toml): locks that block traffic, unsafe changes.
scripts/ci/squawk_migrations.sh "$BASE"
fi

# The CircleCI orb's scripts (clients/circleci-orb), rendered and linted: validating it with CircleCI needs a token.
Expand Down
16 changes: 16 additions & 0 deletions .squawk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Squawk (scripts/ci/squawk_migrations.sh): Postgres migration lint on the SQL of each new migration in
# app/database/migrations, in CI's migrations job. Every rule applies except these, each with its reason.
pg_version = "17.0"
# laravel-rust runs each migration in a transaction, so CREATE INDEX CONCURRENTLY isn't possible: an index on an existing
# table blocks its writes while it builds. On a small table, silence require-concurrent-index-creation with a listed
# `-- squawk-ignore` and the table's size as the reason.
assume_in_transaction = true
excluded_rules = [
# scripts/ci/migration_safety.py owns dropped columns: it fails one main's code still reads and allows the rest.
"ban-drop-column",
# BIGSERIAL keys and integer counters are the schema's convention since the initial migration.
"prefer-identity",
"prefer-bigint-over-int",
# A data backfill may legitimately run long; lock_timeout (required) is what keeps a migration from blocking traffic.
"require-statement-timeout",
]
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ design is in `docs/design.md`; read it before changing the architecture, and upd
is on main. If another branch's migration merged first with a later timestamp, rename yours to a newer one before
merging. A migration on main is never edited either (deployed databases won't run it again): fix it with a new one.
scripts/ci/check_migrations.sh checks all of this in CI's `migrations` job.
- **New migrations are linted by Squawk** (`.squawk.toml`, `scripts/ci/squawk_migrations.sh`, in the hook and the
`migrations` job): start each with `SET LOCAL lock_timeout = '5s';`, and add a foreign key to an existing table
`NOT VALID`, then `VALIDATE` it in a later migration. Silence a finding only with `-- squawk-ignore <rule>` above the
statement, listed with its reason in `scripts/ci/suppressions.txt`.
- The server connects with sqlx's prepared-statement cache off (`config::without_statement_cache`): a migration that
adds a column makes Postgres refuse an old pod's cached `SELECT table.*` ("cached plan must not change result type").
Keep it off. `tests/rollouts.rs` fails if it comes back on. (4 Dec 2026, #178's rollout.)
Expand Down
4 changes: 4 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pre-commit:
run: scripts/ci/check_file_length.py {staged_files}
suppressions:
run: scripts/ci/check_suppressions.py
# Squawk on staged migrations' SQL (.squawk.toml).
squawk:
glob: "app/database/migrations/*.rs"
run: scripts/ci/squawk_migrations.sh --files {staged_files}
# The workflows and actions: actionlint (with shellcheck on their scripts) and zizmor (.github/zizmor.yml).
actionlint:
glob: ".github/workflows/*.{yml,yaml}"
Expand Down
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ hadolint = "2.15.1"
typos = "1.53.0"
oxlint = "1.96.0"
lychee = "0.24.2"
"github:sbdchd/squawk" = "2.74.0"
1 change: 1 addition & 0 deletions scripts/ci/check_suppressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
r"hadolint ignore=[\w,]+",
r"--ignore DL\d{4}",
r"nosemgrep",
r"squawk-ignore(?: [\w-]+(?:, ?[\w-]+)*)?",
r"(?:gitleaks|betterleaks):allow",
]
# Case-insensitive: `# NOQA` silences as well as `# noqa`.
Expand Down
51 changes: 51 additions & 0 deletions scripts/ci/squawk_migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Squawk (.squawk.toml) on the SQL of each migration added since a base commit, or of the migrations named. The SQL
# lives in Rust strings (raw-string consts, or literals passed straight to tx.query), so each file's are copied into a
# .sql file first; a migration whose SQL can't be found that way (a format! string) fails. Old
# migrations aren't checked: production ran them long ago. Silence one finding with `-- squawk-ignore <rule>` above the
# statement, listed with its reason in scripts/ci/suppressions.txt.
#
# scripts/ci/squawk_migrations.sh <base commit>
# scripts/ci/squawk_migrations.sh --files <migration.rs>...
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
if [ "${1-}" = --files ]; then
shift
files=("$@")
else
mapfile -t files < <(git diff --name-only --diff-filter=A "${1:?base commit}" -- 'app/database/migrations/*.rs')
fi
if [ ${#files[@]} -eq 0 ]; then
echo "Squawk: no new migrations."
exit 0
fi
out=$(mktemp -d)
trap 'rm -rf "$out"' EXIT
python3 - "$out" "${files[@]}" <<'PY'
import os, re, sys

# Rust string escapes in a plain "..." literal: a backslash-newline drops the newline and the next line's indent.
ESCAPES = {"n": "\n", "t": "\t", "r": "\r", "0": "\0", "\\": "\\", '"': '"', "'": "'"}


def plain(body):
body = re.sub(r"\\\n\s*", "", body)
return re.sub(r"\\(.)", lambda m: ESCAPES.get(m.group(1), m.group(0)), body)


out, failed = sys.argv[1], False
for path in sys.argv[2:]:
source = open(path).read()
# Raw strings anywhere (the SQL consts), and plain strings passed straight to .query(...).
parts = [m.group(2) for m in re.finditer(r'\br(#*)"(.*?)"\1', source, re.S)]
parts += [plain(m.group(1)) for m in re.finditer(r'\.query\(\s*"((?:[^"\\]|\\.)*)"', source, re.S)]
sql = "\n".join(p if p.rstrip().endswith(";") else p.rstrip() + ";" for p in parts if p.strip())
if not sql.strip():
print(f"{path}: no SQL found. Write it as a literal string, in a raw-string const or passed straight to "
"tx.query(...), so Squawk can read it (a format! string can't be checked).", file=sys.stderr)
failed = True
open(os.path.join(out, os.path.basename(path)[:-3] + ".sql"), "w").write(sql + "\n")
sys.exit(1 if failed else 0)
PY
squawk --config .squawk.toml "$out"/*.sql
echo "Squawk: ${#files[@]} new migrations clean."
2 changes: 2 additions & 0 deletions scripts/ci/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
.github/workflows/release-gallery-python.yml zizmor: ignore[cache-poisoning] -- setup-node there sets no cache; zizmor flags the action itself
.github/workflows/release.yml zizmor: ignore[dangerous-triggers] -- workflow_run is how the release waits for CI; every job checks for a successful CI run of a push to main
.github/zizmor.yml zizmor: ignore[audit] -- not a suppression: the file's comment showing the syntax
scripts/ci/squawk_migrations.sh squawk-ignore -- not a suppression: the script's comment showing the syntax
.squawk.toml squawk-ignore -- not a suppression: the comment telling a migration how to write one
clients/github-action/action.yml zizmor: ignore[github-env] -- GITHUB_PATH gets a directory under RUNNER_TEMP named from the workflow author's own inputs

# docker/renderer.Dockerfile's two hadolint warnings wait for the renderer's next rebuild (sc-9674): any edit to that file rebuilds the renderer image.
Expand Down
Loading