CREATE/DROP INDEX CONCURRENTLY and REINDEX ... CONCURRENTLY cannot run
inside a Postgres transaction block -- it's a hard error ("cannot run
inside a transaction block"), not a lock-duration risk, and it aborts
the whole transaction including every earlier statement already run in
it. Verified against a real local Postgres 14: a migration file with
`BEGIN; ALTER TABLE ...; CREATE INDEX CONCURRENTLY ...; COMMIT;` really
does fail exactly that way and rolls back the ALTER TABLE with it.
Until now SchemaProof never caught this at all -- `applyRules()` only
ever sees one statement at a time (libpg_query parses BEGIN/COMMIT as
their own TransactionStmt nodes), and the existing CREATE INDEX rule
explicitly skips CONCURRENTLY statements since they're normally the
*safe* rewrite. Checked `check` against that exact file before this
change: zero findings, exit code 0 (INFO) -- a false "safe" verdict for
a migration that is guaranteed to blow up in CI.
Adds a whole-file pass (`applyFileLevelRules`) that tracks explicit
BEGIN/COMMIT boundaries across the full statement list and flags any
CONCURRENTLY operation found inside one as `block`
(`concurrently-inside-transaction-block`). Also flags the softer but
common real case -- no explicit BEGIN in the file, but multiple
statements sharing it -- as `caution`
(`concurrently-may-run-inside-framework-transaction`), since Rails,
Prisma Migrate, Flyway, and node-pg-migrate all wrap a migration file
in one implicit transaction by default, which fails the exact same way.
Also fixes a stale --help reference to templates/github-action.yml,
which was intentionally removed in 83a9831 but left dangling in the
CLI's own usage text.
Verified end-to-end against a real local Postgres 14 instance
(schemaproof_test db): the exact BEGIN/CREATE INDEX CONCURRENTLY/COMMIT
repro now reports BLOCK/exit 2 instead of INFO/exit 0, confirmed the
real Postgres error text matches
("CREATE INDEX CONCURRENTLY cannot run inside a transaction block"),
confirmed DROP INDEX CONCURRENTLY inside BEGIN is caught the same way,
confirmed a standalone CONCURRENTLY statement (no other statements in
the file) stays clean INFO/exit 0 (no false positive), confirmed the
implicit multi-statement case correctly downgrades to CAUTION/exit 1,
and re-ran both existing examples/*.sql fixtures with and without
--db and --pr-comment to confirm no regressions in existing rules.
`npx tsc --noEmit` clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
50 lines
1.1 KiB
JSON
50 lines
1.1 KiB
JSON
{
|
|
"name": "schemaproof",
|
|
"version": "0.2.0",
|
|
"description": "Know what your Postgres migration will actually do to YOUR table, right now — real lock classification plus a live read of your database's real row counts, dead-tuple ratio and active blockers (Supabase, Neon, or plain Postgres), with an optional AI-written safe rewrite.",
|
|
"license": "MIT",
|
|
"type": "module",
|
|
"bin": {
|
|
"schemaproof": "./bin/schemaproof.mjs"
|
|
},
|
|
"files": [
|
|
"dist",
|
|
"bin"
|
|
],
|
|
"scripts": {
|
|
"build": "tsc -p tsconfig.json",
|
|
"check": "tsx src/cli.ts",
|
|
"dev": "tsx src/cli.ts"
|
|
},
|
|
"dependencies": {
|
|
"libpg-query": "^17.7.4",
|
|
"pg": "^8.13.1"
|
|
},
|
|
"optionalDependencies": {
|
|
"@anthropic-ai/sdk": "^0.32.1"
|
|
},
|
|
"devDependencies": {
|
|
"@types/node": "^22.10.2",
|
|
"@types/pg": "^8.11.10",
|
|
"tsx": "^4.19.2",
|
|
"typescript": "^5.7.2"
|
|
},
|
|
"engines": {
|
|
"node": ">=18"
|
|
},
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/caelum0x/schemaproof"
|
|
},
|
|
"keywords": [
|
|
"postgres",
|
|
"postgresql",
|
|
"migration",
|
|
"supabase",
|
|
"neon",
|
|
"schema",
|
|
"linter",
|
|
"zero-downtime"
|
|
]
|
|
}
|