You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/content/docs/guides/integrations/pgfence.mdx
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ metaDescription: Learn how to analyze Prisma migration SQL files with pgfence to
8
8
9
9
## Introduction
10
10
11
-
[pgfence](https://pgfence.dev) is a PostgreSQL migration safety CLI that analyzes SQL migration files and reports lock modes, risk levels, and safe rewrite recipes. It uses PostgreSQL's actual parser ([libpg-query](https://github.com/pganalyze/libpg-query-node)) to understand exactly what each DDL statement does, what locks it acquires, and what it blocks.
11
+
[pgfence](https://pgfence.com) is a PostgreSQL migration safety CLI that analyzes SQL migration files and reports lock modes, risk levels, and safe rewrite recipes. It uses PostgreSQL's actual parser ([libpg-query](https://github.com/pganalyze/libpg-query-node)) to understand exactly what each DDL statement does, what locks it acquires, and what it blocks.
12
12
13
13
Prisma Migrate generates plain SQL files at `prisma/migrations/*/migration.sql`. pgfence can analyze those files directly, catching dangerous patterns before they reach production.
14
14
@@ -32,15 +32,15 @@ For each dangerous pattern, pgfence provides the exact safe alternative -- the e
32
32
Add pgfence as a development dependency in your project:
pgfence will flag this as a `MEDIUM` risk because `CREATE INDEX` takes a `SHARE` lock, which blocks all writes to the table for the duration of the index build. It will suggest using `CREATE INDEX CONCURRENTLY` instead.
@@ -78,13 +78,13 @@ Prisma Migrate does not generate `CONCURRENTLY` variants automatically. If pgfen
78
78
pgfence supports JSON output, which is useful for integrating with other tools or scripts:
You can also set a maximum risk threshold for CI pipelines. The command exits with code 1 if any statement exceeds the threshold:
85
85
86
86
```bash
87
-
npx --yes @flvmnt/pgfence@0.2.1 analyze --ci --max-risk medium prisma/migrations/**/migration.sql
87
+
npx --yes @flvmnt/pgfence@0.2.3 analyze --ci --max-risk medium prisma/migrations/**/migration.sql
88
88
```
89
89
90
90
## 4. Add pgfence to your CI pipeline
@@ -119,7 +119,7 @@ jobs:
119
119
- name: Run pgfence analysis
120
120
run: |
121
121
shopt -s globstar
122
-
npx --yes @flvmnt/pgfence@0.2.1 analyze --ci --max-risk medium prisma/migrations/**/migration.sql
122
+
npx --yes @flvmnt/pgfence@0.2.3 analyze --ci --max-risk medium prisma/migrations/**/migration.sql
123
123
```
124
124
125
125
This workflow only triggers when migration files change. If pgfence detects any statement with risk higher than `MEDIUM`, the check fails and blocks the pull request from merging.
@@ -136,7 +136,7 @@ If you have an existing deployment workflow, add pgfence as a step before `prism
136
136
- name: Run pgfence migration safety check
137
137
run: |
138
138
shopt -s globstar
139
-
npx --yes @flvmnt/pgfence@0.2.1 analyze --ci --max-risk medium prisma/migrations/**/migration.sql
139
+
npx --yes @flvmnt/pgfence@0.2.3 analyze --ci --max-risk medium prisma/migrations/**/migration.sql
140
140
141
141
- name: Apply pending migrations
142
142
run: npx prisma migrate deploy
@@ -151,10 +151,10 @@ pgfence can adjust risk levels based on actual table sizes. A `CREATE INDEX` on
151
151
To use size-aware scoring without giving pgfence direct database access, export a stats snapshot from your database and pass it to pgfence:
The stats file contains row counts and table sizes from `pg_stat_user_tables`. Run `npx --yes @flvmnt/pgfence@0.2.1 extract-stats --db-url <connection-string>` to generate this file, or see the [pgfence README](https://github.com/flvmnt/pgfence#db-size-aware-risk-scoring) for details.
157
+
The stats file contains row counts and table sizes from `pg_stat_user_tables`. Run `npx --yes @flvmnt/pgfence@0.2.3 extract-stats --db-url <connection-string>` to generate this file, or see the [pgfence README](https://github.com/flvmnt/pgfence#db-size-aware-risk-scoring) for details.
0 commit comments