-
Notifications
You must be signed in to change notification settings - Fork 835
fix(api): warn when deployed schema drifts from schema.prisma #88
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 all commits
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 |
|---|---|---|
|
|
@@ -113,6 +113,28 @@ builds, and the pages that touch them fail. Test schema changes locally, where | |
| worse: every preview applied its own migrations to the production database, so on | ||
| 2026-08-07 the live schema ran six migrations ahead of the live code all day. | ||
|
|
||
| ### `migrate deploy` is not proof the schema is right | ||
|
|
||
| The build follows the deploy with `prisma migrate diff --exit-code` against | ||
| `schema.prisma` and shouts in the build log when they disagree. **`No pending | ||
| migrations to apply` only means `_prisma_migrations` has a row for every file** — | ||
| it says nothing about what the tables actually look like. | ||
|
|
||
| They came apart once. A `prisma db push` shaped production from a laptop, the | ||
| migration rows were recorded as applied without their SQL ever running, and | ||
| `agentConversationAttachment` went live without its `position` column. Every deploy | ||
| reported nothing pending, for days, while `conversations.builderById` returned 500. | ||
| The tell is an object in the database that no migration defines — there was an | ||
| `agentConversationAttachment_submissionId_createdAt_idx` that appears in no | ||
| migration file, only in a `db push` of an older schema. | ||
|
|
||
| Reconciling is one command, and it is worth reading before running: | ||
|
|
||
| ```sh | ||
| DATABASE_URL="…" bunx prisma migrate diff \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The reconcile command uses Prompt for AI agents |
||
| --from-config-datasource --to-schema prisma/schema.prisma --script | ||
| ``` | ||
|
|
||
| ## Secrets hygiene | ||
|
|
||
| `.gitignore` ignores `.env` and `.env.*` with one negation for `.env.example`, so | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
P2: The drift diff output is captured with
spawnSyncand all defaults, which caps both stdout and stderr at Node's 1 MiBmaxBuffer. This check is specifically meant to surface exactly the case where the two schemas disagree — the human-readable summary printed viadrift.stdoutgrows with the number of differing tables/columns. If a real drift produces output across the 1 MiB limit,spawnSyncthrows aRangeError: stdout maxBuffer length exceededand the whole build script dies, turning a by-design non-fatal warning into a broken deploy. Consider raisingmaxBuffer(and, optionally, explicitly treating a spawn failure so it still only warns).Prompt for AI agents