GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Studio reads the migration ledger from the `_prisma` schema, and falls back to `prisma_contract` by wmadden-electric · Pull Request #1606 · prisma/studio

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Nov 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

At a glance

Studio's Migrations view shows the migrations Prisma ORM 8 has applied to a PostgreSQL database. It reads two tables the ORM keeps for itself in that database: ledger, one row per migration applied, and contract, which stores the contract (the ORM's description of the database's structure) before and after each one. Today Studio looks for them in one schema:

-- before
select … from "prisma_contract"."ledger" l
left join "prisma_contract"."contract" cb on cb."core_hash" = l."origin_core_hash"

The next Prisma ORM release after 8.0.0-rc.25 renames that schema to _prisma. It is not published yet. Once it is, Studio as it is today finds no prisma_contract.ledger in a renamed database and hides the Migrations view.

With this change Studio first works out which schema holds the ledger, then runs the same queries against it:

-- after, on a renamed database
select … from "_prisma"."ledger" l
left join "_prisma"."contract" cb on cb."core_hash" = l."origin_core_hash"
The database has Studio reads
_prisma.ledger _prisma
only prisma_contract.ledger prisma_contract
both _prisma
neither nothing; the Migrations view and its navigation item are hidden, as today

This removes three exports from a published entry point. @prisma/studio-core/data/migrations no longer exports LEDGER_QUERY, LEDGER_QUERY_WITHOUT_CONTRACT and LEDGER_PROBE_QUERY. Details are below.

Decision

Studio reads _prisma, and falls back to prisma_contract when _prisma has no ledger.

The ORM renames the schema itself, the first time a command that changes the database (prisma db migrate, db update, db init or db sign) runs with the release that has the rename. Until a database's owner has run one, the database still has prisma_contract, with the same tables and columns. So once that ORM release is out, real databases of both forms exist, and Studio has to show the history of both.

This repository's rules forbid compatibility fallbacks unless one is asked for. This one is asked for by the ORM work that does the rename, for the reason above, and Architecture/migrations-view.md now records it as a deliberate exception. It is removed when Studio stops supporting databases written by a Prisma ORM 8 release candidate. No date is set for that, because Studio has no stated policy on it yet.

Order of releases. This can merge and be released now: on every database that exists today it reads prisma_contract, exactly as before. It should be released before the ORM release that renames the schema, or users of that release lose the Migrations view until they update Studio. The same holds for Console (prisma/pdp-control-plane), which calls readRecordedSchema from this package: it needs the Studio release with this change before the ORM release ships.

A database has both schemas only when something went wrong, for example when an older ORM command-line tool is run against a database that was already renamed, which creates a fresh, empty prisma_contract beside _prisma. _prisma is the one the current ORM writes to, so it wins.

Why the ORM renames the schema

Every schema, table or collection Prisma ORM 8 puts at the top level of a user's database will have a name that begins _prisma, so a user can tell from the name that it is Prisma's and not to be edited by hand. On PostgreSQL that is the schema; the tables inside it, ledger and contract, keep their names and columns. The name cannot change after 8.0.0 without a major version, so it changes now. The ORM work is Linear ticket TML-3978, "Prisma 8 keeps its own database tables up to date in each release, under names that begin _prisma".

How it works

Paths are from the repository root.

  • One rule, in one place. A new internal module, data/prisma-tables-schema.ts, holds the two schema names, the rule that picks one (the first of _prisma, prisma_contract that has a ledger table), and the ledger queries as functions of the schema. The schema is always one of those two constants, so nothing a user supplies reaches the SQL.
  • The Migrations view and its navigation item (ui/hooks/use-migrations.ts) apply the rule to the list of tables Studio has already loaded for the database, so the choice is made once per load of that list. Two queries then use the chosen schema: a cheap one that asks whether the ledger has any rows, which decides whether the navigation item appears, and the one that loads the ledger. The schema is part of both cache keys, so a result cached for one schema is never shown for the other.
  • readRecordedSchema (data/migrations.ts) returns the contract of the latest applied migration; Console uses it to compare a database with its recorded structure. It already asked PostgreSQL in one query whether the two tables exist. That query now asks about both schemas, and the same rule picks one.
  • A ledger without a contract table. The contract table is newer than the ledger, so Studio already handled a schema that has ledger and no contract: it shows the list of migrations without the before-and-after comparison. That still holds per schema. If _prisma has a ledger and no contract table while prisma_contract has both, Studio reads _prisma only; it never joins one schema's ledger to the other's contracts.

Incidental: the demo seed (demo/ppg-dev/seed-migrations.ts) now writes _prisma, since it stands for a current database. Its code for upgrading an older demo database in place is deleted. The demo database is created fresh on every run, so that code had nothing to upgrade.

The removed exports

@prisma/studio-core/data/migrations exported three SQL strings: LEDGER_QUERY, LEDGER_QUERY_WITHOUT_CONTRACT and LEDGER_PROBE_QUERY. Each named one schema, so none can be correct for both forms of database. They are removed and nothing public replaces them; the queries are now internal. readRecordedSchema, parseLedgerRows and the types are unchanged.

A code search of the prisma organisation on GitHub finds the three names only in this repository. Console imports this entry point, but uses readRecordedSchema, not the constants. I did not search outside the organisation.

The changeset is a minor bump, which is how this package, at 0.35.0, marks a breaking change.

How it was checked

  • data/migrations.postgres.test.ts runs every query against a real PostgreSQL (PGlite) for each schema, and one case has both schemas and asserts _prisma is read.
  • data/migrations.test.ts covers readRecordedSchema for each schema, and the case where _prisma has a ledger and no contract table while prisma_contract has both.
  • ui/hooks/use-migrations.queries.test.tsx renders the hooks with a database adapter that records SQL. It asserts that both queries go to the detected schema only, and that the schema is in the cache keys.
  • Each new test was seen to fail with the behaviour it covers broken.
  • Run locally: the seven test files touched or nearby (80 tests), tsc --noEmit, and ESLint on the changed files. The whole suite and check:exports are left to CI.

The demo, in a browser. AGENTS.md asks for a browser check of the demo on UI changes. I checked this pull request's own preview deployment (the demo service that the deploy check builds from this branch, whose database is seeded into _prisma): the Migrations item is in the navigation, the view lists all 20 seeded migrations, selecting one draws its before-and-after comparison, and the browser console shows no errors. I could not run pnpm demo:ppg locally: on the machine this was built on, the demo fails while seeding its database (bind message supplies N parameters, but prepared statement "" requires 0), and it fails the same way with the seed file from main, so this change did not cause it. I have not found the cause and have filed nothing for it.

Alternatives considered

  • Read only _prisma, and release Studio at the same moment as the ORM. Rejected: the rename happens per database, when its owner next runs a command that changes it, not at the release. A database last changed by a release candidate would lose its Migrations view until then.
  • Query _prisma and retry against prisma_contract on an error. Rejected: Studio already knows which tables exist, and an error can mean something else.
  • Keep the three constants, deprecated, for a release. Rejected: a constant names one schema, so on a renamed database a caller of the deprecated constant would silently read nothing. Removing them makes such a caller fail at build time, and no caller was found.

Agent: laozi-26

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
wmadden-electric and others added 4 commits November 26, 2026 23:54
@wmadden-electric @claude
Read Prisma's migration tables from _prisma, falling back to prisma_c…
fe68e97
…ontract

Prisma ORM 8.0.0 renames the schema that holds its own tables from
prisma_contract to _prisma, the first time a command that changes the
database runs. Until then a database still has prisma_contract, so the
Migrations view, its navigation item and readRecordedSchema now read
_prisma when it holds a ledger and prisma_contract otherwise.

The choice is made once per load from the existing checks: introspection
for the Migrations view, and one to_regclass probe over both schemas for
readRecordedSchema. The ledger queries become functions of one of the
two fixed schema names. The demo seed writes _prisma.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
Keep the schema choice internal and drop the dead demo upgrade
8ad67d3
The schema constants, the choice between _prisma and prisma_contract and
the ledger query builders move to data/prisma-tables-schema.ts, which is
not a build entry, so they are not published. The public
data/migrations module keeps readRecordedSchema, parseLedgerRows and the
types.

The readRecordedSchema probe columns now say which schema they describe
(current_schema_has_ledger and so on). New tests cover the hooks: the
row probe and the ledger load query the schema detection chose and carry
it in their query keys. Another covers _prisma having a ledger without a
contract store while prisma_contract has both.

The demo seed's in-place upgrade looked for old layouts in _prisma,
which nothing ever wrote; the demo database is fresh each run, so it is
removed. The architecture doc says why the prisma_contract fallback
exists and when it is removed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
State the both-schemas rule exactly in the changeset
1c6086b
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge remote-tracking branch 'origin/main' into read-prisma-schema
09e4289
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • New Features
    • The Migrations view now detects migration history in either supported Prisma schema. When both contain a ledger, it uses the legacy schema; if the selected ledger lacks contract data, Studio reports that status.
  • Documentation
    • Updated migration documentation to describe schema selection and compatibility behavior.
  • Chores
    • Demo migration data is now seeded in _prisma; automatic conversion of legacy demo data is no longer performed.

Walkthrough

Migration readers and UI hooks now detect Prisma migration tables in _prisma and prisma_contract and use schema-specific queries. The data reader prefers _prisma when it contains a ledger and otherwise uses prisma_contract. Demo seeding writes migration data to _prisma; the legacy conversion helper and three exported query constants are removed. Documentation describes the schema behavior and migration navigation visibility.

Merge Risk: Minimal · up to 09e42

Studio now reads the migration ledger from _prisma and falls back to prisma_contract, with matching query, hook and demo-seed changes and test coverage for both schemas. No concrete defect remains after review. External code that imports the three removed ledger query constants will need to switch to readRecordedSchema, as the changeset notes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: Studio reads the migration ledger from the _prisma schema and falls back to prisma_contract. The raw summary and objectives confirm this is the primary change in …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is specific and directly related to the changeset. It explains that Studio now reads the Prisma ORM migration ledger from the _prisma schema and falls back to prisma_contract, and …
Full details: Title check

Explanation

The title states the main change: Studio reads the migration ledger from the _prisma schema and falls back to prisma_contract. The raw summary and objectives confirm this is the primary change in the changeset. The title is 96 characters, which is long, but it stays specific and clear.

Full details: Description check

Explanation

The description is specific and directly related to the changeset. It explains that Studio now reads the Prisma ORM migration ledger from the _prisma schema and falls back to prisma_contract, and it covers the removed LEDGER_QUERY, LEDGER_QUERY_WITHOUT_CONTRACT and LEDGER_PROBE_QUERY exports, the release ordering, the new data/prisma-tables-schema.ts module, and the tests run. The description matches the raw summary and objectives.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8560eae3-4af4-4ea8-9369-f01d4b713283
Commits

Reviewing files that changed from the base of the PR and between fa155c3 and 09e4289.

Files selected for processing: 13

  • .changeset/read-prisma-schema.md
  • Architecture/migrations-view.md
  • FEATURES.md
  • data/migrations.postgres.test.ts
  • data/migrations.test.ts
  • data/migrations.ts
  • data/prisma-tables-schema.ts
  • demo/ppg-dev/seed-migrations.ts
  • ui/hooks/react-query.ts
  • ui/hooks/use-migrations.queries.test.tsx
  • ui/hooks/use-migrations.test.ts
  • ui/hooks/use-migrations.ts
  • ui/studio/Navigation.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Compute preview deployed with Prisma Composer.

Stage: read-prisma-schema
Service: demo
Preview: https://ddjntpr6rdpqc781tv7y5fy9.sin.prisma.build

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

coderabbitai[bot]
coderabbitai Bot approved these changes Nov 26, 2026
View reviewed changes
wmadden
wmadden approved these changes Nov 27, 2026
View reviewed changes
@wmadden-electric
wmadden-electric merged commit d2e66d4 into main Nov 27, 2026
2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@wmadden-electric
wmadden-electric deleted the read-prisma-schema branch November 27, 2026 08:15
@wmadden-electric wmadden-electric mentioned this pull request Nov 27, 2026
feat(postgres)!: Prisma's own tables move to schema _prisma and are brought up to date before every command that changes a database prisma/orm#31234
Draft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@wmadden wmadden wmadden approved these changes
@coderabbitai coderabbitai[bot] coderabbitai[bot] approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@wmadden-electric @wmadden
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.