pgsafe 0.0.0-stage → 2.7.1

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.
Files changed (58) hide show
  1. package/ALL-MILESTONES-TESTING.md +41 -0
  2. package/CHANGELOG.md +88 -0
  3. package/CONTRIBUTING.md +3 -0
  4. package/LICENSE +9 -0
  5. package/README.md +254 -2
  6. package/SECURITY.md +13 -0
  7. package/bin/cli.js +120 -0
  8. package/docs/RULES.md +31 -0
  9. package/examples/baseline.sql +7 -0
  10. package/examples/consumer-workflow.yml +22 -0
  11. package/examples/migrations/001_add_phone.sql +1 -0
  12. package/examples/migrations/002_add_email_index.sql +1 -0
  13. package/examples/reviewed-risk-baseline.json +7 -0
  14. package/examples/safe.sql +2 -0
  15. package/examples/suppression-gate-policy.json +11 -0
  16. package/examples/team-policy.json +7 -0
  17. package/examples/test-unsafe.sql +1 -0
  18. package/examples/unsafe.sql +2 -0
  19. package/examples/verify.sql +8 -0
  20. package/examples/week3-gate-policy.json +6 -0
  21. package/examples/week3-production-context.json +8 -0
  22. package/package.json +71 -4
  23. package/scripts/orm-runner/README.md +35 -0
  24. package/scripts/orm-runner/package-lock.json +659 -0
  25. package/scripts/orm-runner/package.json +14 -0
  26. package/scripts/orm-runner/verify.mjs +360 -0
  27. package/scripts/test-pg-matrix.cjs +30 -0
  28. package/src/advisor.js +77 -0
  29. package/src/analysis.js +411 -0
  30. package/src/combined.js +60 -0
  31. package/src/config.js +38 -0
  32. package/src/db-inspect.js +30 -0
  33. package/src/detector.js +25 -0
  34. package/src/engine.js +48 -0
  35. package/src/gitDiff.js +33 -0
  36. package/src/github.js +17 -0
  37. package/src/locks.js +134 -0
  38. package/src/parser.js +86 -0
  39. package/src/plans.js +9 -0
  40. package/src/presets.js +5 -0
  41. package/src/production-context.js +78 -0
  42. package/src/reports.js +38 -0
  43. package/src/risk-baseline.js +54 -0
  44. package/src/risk.js +29 -0
  45. package/src/rules/additionalRules.js +9 -0
  46. package/src/rules/alterTableRules.js +65 -0
  47. package/src/rules/concurrentIndex.js +18 -0
  48. package/src/rules/dataIntegrityRules.js +40 -0
  49. package/src/rules/dropColumn.js +12 -0
  50. package/src/rules/operationalRiskRules.js +57 -0
  51. package/src/rules/ruleCatalog.js +37 -0
  52. package/src/rules/versionCatalog.js +16 -0
  53. package/src/rules/versionRules.js +49 -0
  54. package/src/simulator.js +135 -0
  55. package/src/suppression-matcher.js +24 -0
  56. package/src/suppression-report.js +19 -0
  57. package/src/suppression.js +78 -0
  58. package/src/team-policy.js +84 -0
@@ -0,0 +1,8 @@
1
+ DO $$ BEGIN
2
+ IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='users' AND column_name='phone') THEN
3
+ RAISE EXCEPTION 'users.phone missing';
4
+ END IF;
5
+ IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname='idx_users_email') THEN
6
+ RAISE EXCEPTION 'email index missing';
7
+ END IF;
8
+ END $$;
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "pull-request-static-gate",
3
+ "blockedRules": ["PG001", "PG002", "PG003"],
4
+ "maxWarnings": 5,
5
+ "maxRiskScore": 60
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "tables": [
4
+ { "schema": "public", "table": "users", "estimatedRows": 1200000, "bytes": 2147483648, "writeQueriesPerSecond": 25 }
5
+ ],
6
+ "lockTimeoutMs": 2000,
7
+ "statementTimeoutMs": 300000
8
+ }
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "pgsafe",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.7.1",
4
+ "description": "Detect risky PostgreSQL schema migrations before deployment: SQL linting, lock analysis, risk scoring and CI reports for Prisma, Drizzle and Flyway",
5
+ "type": "module",
6
+ "bin": {
7
+ "pgsafe": "bin/cli.js",
8
+ "pg-safe-migrate": "bin/cli.js"
9
+ },
10
+ "scripts": {
11
+ "test": "node --test",
12
+ "test:unit": "node scripts/run-unit-tests.cjs",
13
+ "test:integration": "node scripts/test-pg-matrix.cjs",
14
+ "lint": "node bin/cli.js",
15
+ "pack:check": "npm pack --dry-run",
16
+ "test:release": "npm run test:unit && node test/release-smoke.cjs"
17
+ },
18
+ "keywords": [
19
+ "postgresql",
20
+ "postgres",
21
+ "migration",
22
+ "linter",
23
+ "prisma",
24
+ "drizzle",
25
+ "zero-downtime",
26
+ "ast",
27
+ "database-migration",
28
+ "migration-linter",
29
+ "schema-migration",
30
+ "migration-safety",
31
+ "database-safety",
32
+ "postgres-locks",
33
+ "flyway",
34
+ "sarif"
35
+ ],
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "chalk": "^5.3.0",
39
+ "commander": "^12.1.0",
40
+ "libpg-query": "^16.2.1"
41
+ },
42
+ "engines": {
43
+ "node": ">=18.0.0"
44
+ },
45
+ "files": [
46
+ "bin/",
47
+ "src/",
48
+ "README.md",
49
+ "LICENSE",
50
+ "examples/",
51
+ "scripts/test-pg-matrix.cjs",
52
+ "scripts/orm-runner/verify.mjs",
53
+ "scripts/orm-runner/package.json",
54
+ "scripts/orm-runner/package-lock.json",
55
+ "scripts/orm-runner/README.md",
56
+ "ALL-MILESTONES-TESTING.md",
57
+ "CHANGELOG.md",
58
+ "SECURITY.md",
59
+ "CONTRIBUTING.md",
60
+ "docs/RULES.md"
61
+ ],
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/subodhsingh001/pg-safe-migrate.git"
65
+ },
66
+ "bugs": {
67
+ "url": "https://github.com/subodhsingh001/pg-safe-migrate/issues"
68
+ },
69
+ "homepage": "https://github.com/subodhsingh001/pg-safe-migrate#readme",
70
+ "publishConfig": {
71
+ "access": "public"
72
+ }
73
+ }
@@ -0,0 +1,35 @@
1
+ # Optional real ORM migration verification
2
+
3
+ This integration test runs **actual Prisma Migrate and Drizzle ORM migration runners** against a disposable PostgreSQL database. It is separate from the package's default `npm test` and GitHub Actions workflow.
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js and npm
8
+ - Docker with an available local PostgreSQL port, or another **disposable** PostgreSQL database
9
+ - Dependencies installed in `scripts/orm-runner` with `npm install`
10
+
11
+ ## Windows PowerShell
12
+
13
+ From the repository root:
14
+
15
+ ```powershell
16
+ docker run -d --name pg-safe-orm-test -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=pg_safe_local_test_2026 -e POSTGRES_DB=pg_safe_migrate_test -p 127.0.0.1:55432:5432 postgres:16
17
+ $env:DATABASE_URL = "postgresql://postgres:pg_safe_local_test_2026@127.0.0.1:55432/pg_safe_migrate_test"
18
+ cd scripts/orm-runner
19
+ npm install
20
+ npm run verify
21
+ ```
22
+
23
+ The Docker container command is for an isolated local test only. If the container already exists, start it with `docker start pg-safe-orm-test` instead of creating another one. Stop and remove it when finished with `docker rm -f pg-safe-orm-test`.
24
+
25
+ ## Expected checks
26
+
27
+ 1. Prisma applies a baseline table migration.
28
+ 2. Prisma applies a **separate** concurrent-index migration and the index exists.
29
+ 3. The tested Drizzle node-postgres migrator rejects `CREATE INDEX CONCURRENTLY` inside its transaction with PostgreSQL `25001`.
30
+ 4. The rejected Drizzle index is absent.
31
+ 5. Temporary database schemas and local temporary files are cleaned up.
32
+
33
+ `KEEP_TEST_SCHEMAS=1` retains test schemas for inspection; do not set it during normal verification.
34
+
35
+ **Safety:** This script creates and drops schemas. Run it only against a disposable test database, never a production or shared database. Results depend on the exact Prisma, Drizzle, PostgreSQL, and runner versions installed.