← Back to Pull requests

feat(prisma-cloud)!: deploys always run the ORM's migrate and show the ORM's own error #463

Closed
unknown closed this pull request without merging on Nov 30, 2026 09:10 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 05:50 UTC
Author

A deploy now runs Prisma ORM's prisma db migrate --to <ref> against every ORM database, every time, and lets the ORM decide what to do. When the ORM refuses, the user sees the ORM's whole error instead of a one-line summary.

Before, a failed migration reached the user like this, with the ORM's reason and recovery steps dropped:

OrmMigrationError: Prisma ORM migrate (RUNNER_FAILED): MIGRATION.MARKER_MISMATCH: …

After, Composer writes one line saying what it ran, and the ORM's error follows in full:

✘ [DEPLOY.ENGINE_FAILED] Alchemy could not deploy the app.
shop.database: Composer ran prisma db migrate --to production on this database.
  [MIGRATION.POLICY_MISMATCH] The ref's policies differ from the database's
    why: production declares change: migrate; the database has change: migrate, reconcile.
  → Make the ref match the database, or have whoever owns the database apply the ref's policies.

(The → line is the wording of the ORM version Composer pins today. A newer ORM release, prisma/orm#31214, rewords it; it reaches users when Composer updates the ORM.)

Linked issue

TML-3726 (a failed deploy shows the ORM's own migrate error) and TML-3729 (deploys respect a database's policies). For TML-3729, a deploy now hands the ORM the ref's policies, so the ORM compares them with the database's on every deploy and refuses when they differ. A deploy never changes the database's policies itself; a person does that by hand.

Summary

Two ORM terms this change rests on

  • A ref is a small file committed in the app's repository, migrations/app/refs/<name>.json, usually named after an environment. It names the schema version (the "contract") that the environment's database must reach, and may declare policies: rules the database must follow, such as change: migrate, meaning the database may change only through committed migrations. The user creates and moves refs, for example with prisma migration ref set production <migration>.

  • @contract is the ORM's name for the schema the current commit describes. It needs no ref file.
  • The ORM's model for continuous deployment is one command run on every deploy: prisma db migrate --to <ref>. The ORM works out what to run, does nothing when nothing is pending, and refuses anything the database's policies forbid.

    What Composer did before

    Composer did not follow that model. Before calling the ORM, it read the database itself to decide whether the database was already up to date, and if it judged so it skipped the ORM. When no ref was named, it migrated to the current commit's schema. That check never looked at policies, so a change to a ref's policies alone would never reach the database. To avoid silently ignoring them, Composer refused every ref that declared policies.

    When the ORM did fail, Composer kept only its code and summary. For one failure, a missing migration path, it replaced the ORM's advice with its own. That advice is how an agent came to propose resetting a shared development database whose right fix was prisma db update.

    What Composer does now

    An app names the target on its database. It is required:

    postgres({
      name: 'database',
      contract,
      config: './prisma.config.ts',
      // production deploys go to refs/production.json; `prisma dev` follows the current schema
      targetRef: resolve([environment.name], ([name]) => (name === 'dev' ? '@contract' : name)),
    });
    

    targetRef accepts a ref name or @contract. Other forms the ORM accepts are refused when the node is declared; for example @empty would empty the database.

    On every deploy and every prisma dev rebuild, Composer runs the ORM's migrate to that target and passes the ref whole, policies included. It never gives the ORM consent to change a policy. When a pull request changes a ref's policies, the next deploy fails and changes nothing until whoever administers the database applies them by hand:

    prisma db migrate --to production --permit-policy-change --db <url>
    

    The next deploy then proceeds. The deploy guide says where to get the URL.

    Two smaller behaviour changes come with this:

  • Only connection failures are retried. Before, every ORM error was retried for about a minute before the user saw it.

  • This works for any provider, not only the ORM. The part of Composer that reports a failed deploy now carries a provider's structured error (code, why, next actions, docs link, and the error that caused it) to the prisma deploy output, the prisma dev rebuild message, the --report file and the Prisma Cloud build log. It names no product. The old 1000-character limit is gone.
  • Why services needed rewiring

    A service must start only after its database is migrated. Composer used to get that order by building the connection string a service receives from the migration step's result. Composer's deploy engine treats any value built from a step that will run as possibly changed, so with the migration now running every time, every service using a database would have been redeployed on every deploy.

    The connection string now comes from the database alone. The service's deployment waits for the migration through a separate setting, the same mechanism a service already uses to wait for other services it calls. An unchanged deploy redeploys nothing, on Prisma Cloud and under prisma dev.

    Breaking changes

  • Every app with an ORM database must add targetRef; until then it does not type-check. Then commit a ref for each environment it deploys to, with prisma migration ref set <environment> <newest migration>. The deploy guide has the steps.

  • A new environment other than dev needs a committed ref before its first deploy, when targetRef comes from the environment name.

  • prisma db update inside prisma dev stops working after a schema change. Every rebuild then fails with the ORM's MIGRATION.MARKER_MISMATCH until a migration is planned. The ORM refuses a database that is already at its target when no migration ends there. That is an ORM bug, tracked as TML-3999. Composer adds no check of its own to hide it, and the docs say to plan a migration for each schema change in the meantime.

  • A prisma.config.ts no longer needs a database connection. The examples used a fake address only to fill the field; it is removed.
  • Known limit

    A database that a module provisions for itself targets @contract. Its migrations ship inside the module's package, so an app has nowhere to commit a ref for it. Such a database cannot have policies, and it moves to the module's schema in every environment when the app upgrades the package. This is recorded in the decision record and the project's deferred list.

    Also in this change

  • The examples wire targetRef as above and commit migrations/app/refs/production.json. Shared modules target @contract.

  • Five migration snapshots in the examples were stale. Manual QA found that the old one broke the manual policy step, so all were refreshed.

  • Docs: the decision records on database dependencies and on structured errors, the deploy and building guides, the core-concepts skill, the local development doc, the glossary (new entries for ref and targetRef), and the goals doc (the new-environment requirement above).
  • Testing performed

  • Type-check and lint of each changed package; the touched test files run one at a time. Each new test was checked by breaking the behaviour it guards and watching it fail. They include:

  • - against a local Postgres: a policy mismatch that changes nothing, the manual step, a successful deploy and the new policy enforced; a new database whose ref declares policies; nothing pending; the advised command keeps --to; an ORM refusal is not retried; a replay of the database-reset incident above;
    - a test that runs the real deploy engine and Prisma Cloud resources against a fake Prisma Cloud API: an unchanged deploy replaces no deployment, a first deploy starts each service after its migration, and new code replaces only its own service.
  • Manual QA against Prisma Cloud with examples/orm-demo, in its own environment, destroyed afterwards: first deploy migrated, then started the service (HTTP 200); an unchanged deploy made no new service version; a ref with new policies failed as shown above and changed nothing; the --report file held the structured error; after the manual step, the next deploy succeeded.

  • prisma dev on orm-demo: the first run migrated and started the service; the second updated only the migration step.

  • Two independent reviews of the whole branch, one of the design and one of the code, repeated to the tip, with every finding fixed.
  • Checklist

  • All commits are signed off.

  • The change is scoped to one concern: deploys hand database migration to the ORM. The service rewiring is needed for it.

  • The PR title is a conventional commit, marked breaking.

  • Tests are updated.
  • Notes for the reviewer

    Implementation points worth a look:

  • Next actions are kept as typed objects in the CLI engine's NextAction shape through the --report file and --json output, so a tool can tell a command from advice. Composer declares its own copy of the type, with a type test pinning it to the engine's, because @prisma/composer does not depend on the engine package.

  • Only the copy sent to the Prisma Cloud build log is shortened, to its 5000-character limit, by cutting from the middle of the longest why, so the next actions at the end survive.

  • The ORM writes its binary as a {bin} placeholder in advised commands; Composer fills in prisma.
  • Alternatives considered:

  • Keep Composer's own up-to-date check and teach it about policies. Composer would keep a copy of a decision the ORM makes, and every new ORM feature would need the copy updated.

  • A consent setting on the database node, or a prisma deploy flag. Either stays in place after the change it was meant for, so any later edit to a ref's policies would be applied on merge without anyone deciding it.

  • Default the ref to the environment name or to production. A default either breaks an environment with no ref file, or migrates every environment to production's ref.

  • Write the ORM's why and advice into Composer's error message. Every reporting path would need its own formatting, and other providers' structured errors would still lose their detail.

  • Hand the errors to the CLI engine's own error list. That list has no "caused by" link, so the Composer line with the ORM's error under it would not survive.
  • Design and plan: .drive/projects/deploy-runs-orm-migrate/.

    Agent: scully-11

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: wmadden Review duration: 200m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.75) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #463"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%