-
Notifications
You must be signed in to change notification settings - Fork 916
docs(docs): add pgfence migration safety integration guide #7564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
d1ca076
3415b32
5f97f63
f43a68d
664ee22
a4b5b66
4616bc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| "vercel-deployment", | ||
| "deno", | ||
| "datadog", | ||
| "pgfence", | ||
| "permit-io", | ||
| "shopify", | ||
| "neon-accelerate", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,160 @@ | ||||||
| --- | ||||||
| title: pgfence | ||||||
| description: Analyze Prisma Migrate SQL files for dangerous lock patterns, risk levels, and safe rewrite recipes before deploying to production | ||||||
| url: /guides/integrations/pgfence | ||||||
| metaTitle: How to use pgfence with Prisma Migrate for safe PostgreSQL migrations | ||||||
| metaDescription: Learn how to analyze Prisma migration SQL files with pgfence to detect dangerous lock patterns, understand risk levels, and get safe rewrite recipes before deploying. | ||||||
| --- | ||||||
|
|
||||||
| ## Introduction | ||||||
|
|
||||||
| [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. | ||||||
|
|
||||||
| Prisma Migrate generates plain SQL files at `prisma/migrations/*/migration.sql`. pgfence can analyze those files directly, catching dangerous patterns before they reach production. | ||||||
|
|
||||||
| Common issues pgfence detects include: | ||||||
|
|
||||||
| - `CREATE INDEX` without `CONCURRENTLY` (blocks writes) | ||||||
| - `ALTER COLUMN TYPE` (full table rewrite with `ACCESS EXCLUSIVE` lock) | ||||||
| - `ADD COLUMN ... NOT NULL` without a safe default (blocks reads and writes) | ||||||
| - Missing `lock_timeout` settings (risk of lock queue death spirals) | ||||||
|
|
||||||
| For each dangerous pattern, pgfence provides the exact safe alternative -- the expand/contract sequence you should use instead. | ||||||
|
|
||||||
| ## Prerequisites | ||||||
|
|
||||||
| - [Node.js v20+](https://nodejs.org/) | ||||||
| - A Prisma project using PostgreSQL as the database provider | ||||||
| - Existing migrations in `prisma/migrations/` | ||||||
|
|
||||||
| ## 1. Install pgfence | ||||||
|
|
||||||
| Add pgfence as a development dependency in your project: | ||||||
|
|
||||||
| ```npm | ||||||
| npm install -D @flvmnt/pgfence | ||||||
| ``` | ||||||
|
|
||||||
| ## 2. Analyze your migrations locally | ||||||
|
|
||||||
| Run pgfence against your Prisma migration files: | ||||||
|
|
||||||
| ```bash | ||||||
|
||||||
| ```bash | |
| ```npm |
If possible, use npm instead of bash
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```bash | |
| ```npm |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```bash | |
| ```npm |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```bash | |
| ```npm |
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```bash | |
| ```npm |
Outdated
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link to the Prisma Migrate overview page is incorrect. It should point to "/orm/prisma-migrate" instead of "/orm/prisma-migrate/understanding-prisma-migrate/overview". There is no overview page in the understanding-prisma-migrate subdirectory.
| - [Prisma Migrate overview](/orm/prisma-migrate/understanding-prisma-migrate/overview) | |
| - [Prisma Migrate overview](/orm/prisma-migrate) |
Uh oh!
There was an error while loading. Please reload this page.