docs: baseline a migration history that is behind the schema #8933
All Vouch review confidence checks passed
Residual risk 0.40 = Change Risk (0.75) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #8933"
general
weight: 0.35
ankur-arch
TL;DR
The docs never covered a migration history that is behind the schema, which is what makes
prisma migrate deploycreate only some of the tables on a new database. This PR adds that workflow to the Prisma ORM 6 and 7 baselining pages and replaces>redirection withmigrate diff --output, which already exists and avoids the Windows PowerShell encoding problem.Linear: https://linear.app/prisma-company/issue/DR-9703
Drifted history: detect it, add a catch-up migration, verify
Problem. When tables are created with
db push, the schema and the database agree but theprisma/migrationsfolder cannot recreate the database.migrate deployon an empty database reports success and leaves those tables missing, andmigrate statussaysDatabase schema is up to date!on the drifted database.Fix. A new section, "Baselining a migration history that is behind your schema", on
orm/v7/prisma-migrate/workflows/baseliningand theorm/v6copy. It compares schema with database and history with schema usingmigrate diff --exit-code, writes the missing SQL as a catch-up migration, marks it applied on existing databases withmigrate resolve --applied, and repeats the parity check. Each page uses its own version's flag names.Entry points. The Prisma Postgres import guide, its v7 copy and the Supabase guide link to the section from their "Prisma ORM 7 or earlier" step, and the
migrate diffreference links to it.PowerShell encoding: use
--output, not>Problem. The baselining commands redirected
migrate diff --scriptintomigration.sql. Windows PowerShell 5.1 writes redirected output as UTF-16LE with a BOM, and PostgreSQL rejects a file that starts with a BOM.Fix. The 12 commands that redirected into
prisma/migrations/0_init/migration.sqlnow use--output. A short section documents the symptoms and the repair, and themigrate diffreference gains a "Write the script to a file" example.Also fixed
The two Prisma ORM 6 baselining commands used
--to-schema, which Prisma ORM 6.19.1 rejects withunknown or unexpected option. They now use--to-schema-datamodel.Validation
All commands were run against temporary Prisma Postgres databases (
npx create-db) on macOS with Node 24.11.1, once withprisma@6.19.1and once withprisma@7.10.1.migrate deployon an empty database created onlyUserand exited0.2and lists the 4 missing tables; schema against the drifted database exits0.resolve --appliedon the old database andmigrate deployon the new one, both reportNo difference detected.andmigrate statusis clean. Apg_dumpandpg_restorecopy carried_prisma_migrationswith it.--shadow-database-url. Prisma ORM 7 rejects one indatasource.shadowDatabaseUrlwithP3025, so the v7 page usesprisma dev.--outputwrote plain UTF-8 with no BOM. A file withEF BB BFprepended fails indb execute --file(syntax error at or nearthe BOM character) and inmigrate deploy(P3018, code42601); a UTF-16LE file fails withstring contains embedded null;psql17.6 accepts the UTF-8 BOM file. Recovery withresolve --rolled-backplus a regenerated file was run end to end.about_Character_Encodingfor what>writes.lint:spellcheck,lint:links,lint:versionsandtest:llm-markdownpass, and the edited pages return 200 on a local dev server with the new anchors present.Follow-ups
--to-schemaor--from-schema(squashing, down migrations, patching, Cloudflare D1).migrate diffwith>(down.sql,forward.sql, D1 migrations).P3025for two distinct Prisma Postgres databases andP1001fromdb execute --fileon a UTF-16 file look like tooling issues worth filing.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Changes after review
apps/docs/AGENTS.mdforbids them, so the page no longer says to avoid a Prisma Postgres shadow database because ofP3025, and no longer mentionsP1001fromdb execute --file. The v7 page describes the shadow database by what it must be and shows the local one fromprisma dev. A Prisma Postgres shadow database is left out until the guard is fixed.P3025again with two fresh Prisma Postgres databases on 7.10.1. TML-3976 covers it and notes theP1001case._prisma_migrationsand dropped custom SQL from archived migrations, and it was not tested for those cases. The section covers only the catch-up migration.dotenv/configin the config example, a cleanup step that removesshadowDatabaseUrlbefore the variable is unset, and a one-line--outputexample that also runs in PowerShell.Summary by CodeRabbit
Documentation
Expanded baselining guidance for Prisma ORM 6 and 7, including how to identify and resolve cases where migration history doesn’t include all schema changes.
Clarified how to create catch-up migrations for existing databases and apply them to new databases.
Updated migration examples to use
--outputfor saving SQL files, with guidance on Windows encoding issues and recovery from migration errors.* Added notes about tables created with
prisma db pushthat may be missing from new databases deployed withprisma migrate deploy.<!-- end of auto-generated comment: release notes by coderabbit.ai -->