2 Commits

Author SHA1 Message Date
5c3b2f55df fix: now()/CURRENT_TIMESTAMP/CURRENT_DATE falsely flagged as forcing a table rewrite
add-column-volatile-default treated every non-literal DEFAULT (any FuncCall
or SQLValueFunction) as "possibly volatile" and returned BLOCK, including
`DEFAULT now()` / `CURRENT_TIMESTAMP` / `CURRENT_DATE` -- one of the most
common real-world migration patterns (created_at/updated_at columns).

Verified live against a real seeded Postgres 14 instance (200k-row table,
not guessed from docs): ADD COLUMN ... DEFAULT now()/CURRENT_TIMESTAMP/
CURRENT_DATE left pg_relation_filenode() unchanged and
pg_attribute.atthasmissing=true (fast-default path, no rewrite) -- same as
a literal constant. By contrast DEFAULT random() (genuinely VOLATILE,
pg_proc.provolatile='v') did change the relfilenode and gave existing rows
distinct per-row values -- a real rewrite, confirming gen_random_uuid(),
nextval(...), clock_timestamp() must keep returning BLOCK.

Fix: treat SQLValueFunction nodes (CURRENT_TIMESTAMP/CURRENT_DATE/
CURRENT_TIME/etc.) as safe, and allow-list the now() FuncCall by name (it's
STABLE, not VOLATILE). Re-ran existing examples/safe-migration.sql and
risky-migration.sql -- no regressions (same CAUTION/BLOCK verdicts as
before). Added examples/stable-vs-volatile-default.sql as a real repro.
`npx tsc --noEmit` clean; `npm run build` + compiled bin/schemaproof.mjs
re-verified the same fix end to end.
2026-10-29 02:36:44 +03:00
3eb9b14677 feat: initial SchemaProof CLI — live-database-aware Postgres migration safety checker
Parses migrations with the real Postgres parser (libpg_query via libpg-query),
classifies the lock each statement takes, and — unlike static-only linters
(Squawk, Atlas free tier) — optionally connects to the real target database
(Supabase/Neon/plain Postgres) to re-score severity against that table's
actual row count, dead-tuple ratio, and currently-active lock holders, with
an optional AI explain+rewrite layer gated on ANTHROPIC_API_KEY.

Verified against a real local Postgres with a seeded 150k-row table and a
real concurrent lock holder: same static rule produces BLOCK on the large
table and INFO on a 3-row table, and escalates to BLOCK when a real backend
is holding a lock on the target table at check time.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-26 15:53:29 +03:00