@subodh001/pg-safe-migrate 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -18
- package/bin/cli.js +1 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -1,30 +1,66 @@
|
|
|
1
1
|
# pg-safe-migrate
|
|
2
2
|
|
|
3
|
-
AST-based PostgreSQL migration **risk** linter for Prisma, Drizzle and SQL
|
|
3
|
+
An AST-based PostgreSQL migration **risk** linter for Prisma, Drizzle, and raw SQL. It flags six common migration patterns that may cause blocking locks or application compatibility failures. **It does not guarantee zero downtime.**
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick start
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
npm
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npx --yes --package=@subodh001/pg-safe-migrate@1.1.1 pg-safe-migrate --help
|
|
9
|
+
npm install --save-dev @subodh001/pg-safe-migrate
|
|
10
|
+
npx pg-safe-migrate prisma/migrations
|
|
11
|
+
npx pg-safe-migrate drizzle
|
|
12
|
+
npx pg-safe-migrate db/migrations
|
|
13
|
+
npx pg-safe-migrate --changed origin/main
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
`--changed`
|
|
16
|
+
The default scan searches `prisma/migrations`, `drizzle`, `migrations`, and `db/migrations`. For any other directory, provide its path. `--changed` without a base checks staged, unstaged and untracked SQL; with a base, it additionally checks branch changes. For pull requests, fetch the base branch first (`fetch-depth: 0` in GitHub Actions).
|
|
16
17
|
|
|
17
18
|
## Rules
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
| Rule | Flagged pattern | Reason |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| PG001 | CREATE INDEX without CONCURRENTLY | Blocks writes during index build |
|
|
23
|
+
| PG002 | DROP COLUMN | May break old app versions |
|
|
24
|
+
| PG003 | ALTER COLUMN TYPE | Strong lock and possible rewrite |
|
|
25
|
+
| PG004 | ADD COLUMN NOT NULL without DEFAULT | Backfill/compatibility risk |
|
|
26
|
+
| PG005 | ADD FOREIGN KEY without NOT VALID | Validation can block writes |
|
|
27
|
+
| PG006 | RENAME | May break old app versions |
|
|
28
|
+
|
|
29
|
+
A passing result means **no configured patterns were found**, not that a migration is production-safe. Evaluate PostgreSQL version, lock timeout, data volume, long-running transactions, ORM transaction wrapping, and deployment sequencing separately.
|
|
30
|
+
|
|
31
|
+
## GitHub Actions
|
|
32
|
+
|
|
33
|
+
Copy [`examples/consumer-workflow.yml`](examples/consumer-workflow.yml) into your application's `.github/workflows/pg-safe-migrate.yml`. It checks SQL files changed in a PR and doesn't require fixing historical migrations. Pin the package to an audited version, and upgrade deliberately.
|
|
34
|
+
|
|
35
|
+
## Verify the published CLI
|
|
36
|
+
|
|
37
|
+
From a clean directory:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npx --yes --package=@subodh001/pg-safe-migrate@1.1.1 pg-safe-migrate --help
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Create `unsafe.sql` containing `CREATE INDEX idx_users_email ON users(email);`, then run:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx --yes --package=@subodh001/pg-safe-migrate@1.1.1 pg-safe-migrate unsafe.sql
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Expect `PG001` and exit code 1. The sample `examples/safe.sql` uses `CONCURRENTLY` and should pass PG001; it must run outside a transaction.
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
npm install
|
|
55
|
+
npm test
|
|
56
|
+
node bin/cli.js test/unsafe_migration.sql
|
|
57
|
+
npm pack --dry-run
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For reproducible CI, commit the generated `package-lock.json` and replace `npm install` in the project's CI with `npm ci`.
|
|
25
61
|
|
|
26
|
-
|
|
62
|
+
## Limitations
|
|
27
63
|
|
|
28
|
-
|
|
64
|
+
This is a static AST linter, not a database execution simulator. It does not connect to production, estimate lock wait time, validate migration rollback, or understand the live schema. `--changed` checks changed SQL files, not SQL inside changed JavaScript/TypeScript files. Some flagged operations can be acceptable under controlled conditions, and some unflagged operations can still cause downtime.
|
|
29
65
|
|
|
30
|
-
|
|
66
|
+
MIT licensed. Issues and edge-case reproductions welcome.
|
package/bin/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { getChangedSqlFiles } from '../src/gitDiff.js';
|
|
|
10
10
|
program
|
|
11
11
|
.name('pg-safe-migrate')
|
|
12
12
|
.description('Deterministic AST linter for zero-downtime PostgreSQL migrations')
|
|
13
|
-
.version('1.1.
|
|
13
|
+
.version('1.1.2')
|
|
14
14
|
.argument('[target]', 'Path to a .sql file or migrations directory')
|
|
15
15
|
.option('-c, --changed [baseBranch]', 'Lint changed SQL files (optionally compare with a base ref)')
|
|
16
16
|
.action(async (target, options) => {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subodh001/pg-safe-migrate",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "PostgreSQL AST migration risk linter for Prisma, Drizzle and SQL",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"pg-safe-migrate": "bin/cli.js"
|
|
7
|
+
"pg-safe-migrate": "./bin/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "node --test",
|
|
@@ -35,5 +35,13 @@
|
|
|
35
35
|
"src/",
|
|
36
36
|
"README.md",
|
|
37
37
|
"LICENSE"
|
|
38
|
-
]
|
|
38
|
+
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/subodhsingh001/pg-safe-migrate.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/subodhsingh001/pg-safe-migrate/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/subodhsingh001/pg-safe-migrate#readme"
|
|
39
47
|
}
|