I tested a PostgreSQL migration checker on 760 real migration files
说明与用途
作者在760个迁移文件上测试了静态工具pg-migration-guard,发现1,340个潜在问题,并将其集成到GitHub Actions中,仅检查新更改。
问题
Valid SQL migrations can still cause production issues such as blocking writes or rewriting large tables, yet these problems are hard to detect during code review.
结果
The tool identified 1,340 rule matches across 760 migration files, demonstrating its ability to surface potential safety issues before deployment.
工作流
- 1. Run pg‑migration‑guard on the migration files with the --changed-since flag to limit analysis to the current PR.
- 2. In GitHub Actions, configure the job to trigger on migrations/**/*.sql and run the tool with the appropriate flags.
- 3. The tool outputs GitHub‑style annotations for each finding and exits with a code indicating safety threshold failures.
- 4. Optionally, provide a database URL to enable catalog inspection for severity adjustment.
证据
I used the migration histories from Cal.com and Documenso: 760 SQL migration files, 2,638 SQL statements, 1,340 findings from the initial full-history scan
The CLI now accepts a Git reference: npx pg-migration-guard "migrations/**/*.sql" --changed-since origin/main
The current rules cover a deliberately limited set of PostgreSQL operations: indexes created without CONCURRENTLY, CREATE INDEX CONCURRENTLY inside a transaction, SET NOT NULL on existing tables, column type changes that may rewrite a table, volatile defaults, foreign keys that validate existing rows immediately, table and column removal, ALTER TABLE without a migration-level lock_timeout
- 记录日期: 2026-10-07T12:41:00.253Z