Repository navigation
fix(migrations): read Prisma ORM's tables from the prisma schema, not _prisma - #1615
Merged
Merged
Conversation
Prisma ORM 8.0 names the schema for its own tables prisma, without the underscore. No ORM release ever created _prisma, so Studio stops reading it. Studio reads prisma when it holds a ledger table and falls back to prisma_contract, the name in the ORM 8 release candidates. A schema named prisma that an application created for its own tables is not read as Prisma's unless it holds a ledger table; new tests cover that for readRecordedSchema and for the Migrations detection. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The ORM release that names the schema prisma keeps the applied contract hashes in a signatures table and creates no marker table. The demo seed now creates signatures with that release's columns and fills it from the fixture's marker rows. Studio reads neither table. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…umns An application can own a schema named prisma, and the ORM then keeps its tables in prisma_contract. Two things made such a database lose its history in Studio: - readRecordedSchema probed with to_regclass, which raises an error when the role may not use the prisma schema, so the read failed before the fallback. It now reads the same facts from pg_catalog, as introspection does. - A table of the application's own named ledger made prisma win. A schema now counts as Prisma's only when its ledger table has the migration_hash and destination_core_hash columns. The check lives in choosePrismaTablesSchema, so readRecordedSchema and the Migrations detection share it. New PGlite tests cover both cases, and one writes the name prisma literally so that changing the constant fails it. The architecture doc says what makes a schema count as Prisma's, and two of its sentences are corrected. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Contributor
|
Compute preview deployed with Prisma Composer. Stage: |
wmadden
approved these changes
Nov 28, 2026
…a's tables readRecordedSchema counted regular and partitioned tables, while the introspection behind the Migrations view counts regular tables and views, so the two could choose different schemas. The probe now counts regular tables and views, with a test of a prisma.ledger view. The architecture doc names data/prisma-tables-schema.ts as the internal module, and FEATURES.md says when a prisma schema counts as Prisma's. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden-electric
marked this pull request as draft
November 28, 2026 22:06
wmadden-electric
marked this pull request as ready for review
November 29, 2026 00:16
wmadden-electric
added a commit
to prisma/orm
that referenced
this pull request
Nov 29, 2026
…ma schema yet Studio 0.36.0 reads _prisma, which no release of Prisma uses. The release that reads prisma is the one after prisma/studio#1615 merges; until then the Migrations view is empty on an upgraded database. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden-electric
added a commit
to prisma/orm
that referenced
this pull request
Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden-electric
added a commit
to prisma/orm
that referenced
this pull request
Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
At a glance
Against a PostgreSQL database that Prisma ORM 8.0 has migrated, Studio 0.36.0's Migrations view shows nothing: it looks for the ORM's tables in a schema the ORM does not use. This changes where Studio looks:
Background: where Prisma ORM keeps its own tables
Prisma ORM keeps a few tables for itself in every PostgreSQL database it manages. Studio's Migrations view reads two of them: the ledger, one row per migration applied, and the contract store, which holds the description of the database's structure before and after each migration, so the view can show what a migration changed.
The schema that holds them has had three names:
prisma_contract_prismaprismaStudio 0.36.0 was released ahead of the ORM change and read
_prisma. Before the ORM change shipped, the ORM dropped the leading underscore, so 8.0 usesprisma(prisma/orm#31242). The first command of 8.0 that changes a release candidate's database renamesprisma_contracttoprismain place, so a database has one or the other, never both, unless something else created the second.The decision
Studio reads the ledger from
prismawhen that schema has Prisma's ledger, and otherwise fromprisma_contract. A schema has Prisma's ledger when it has a table or view namedledgerwith the columnsmigration_hashanddestination_core_hash, which Studio reads. When both schemas have one,prismawins, because it is where 8.0 puts the tables.Studio no longer reads
_prisma. No released ORM created it. A developer who tried a preview build of the ORM change has a database with_prisma: Studio shows no history for it, and running a command of any later ORM release does not move it. Such a database is a scratch database; recreate it.An application's own
prismaschemaAn application may have a schema of its own named
prisma. It counts as Prisma's only when it has aledgertable with those columns, so an application'sprismaschema, or an application table that happens to be namedprisma.ledger, is ignored and Studio falls back toprisma_contract. Studio checks this in the system catalogue, so a role that may not use an application'sprismaschema still gets the fallback rather than an error.The ORM itself stops before it renames
prisma_contractwhen a non-emptyprismaalready exists, so such a database keeps its history inprisma_contract, which is where Studio then reads it.Changes
data/prisma-tables-schema.ts: the schema name isprisma, and one function,choosePrismaTablesSchema, decides betweenprismaandprisma_contract. Both places that need the answer use it: the query that reads the history (readRecordedSchema), and the check that decides whether to show the Migrations item in the navigation.to_regclass, which raises an error for a schema the role may not use.Architecture/migrations-view.mdandFEATURES.mdnameprismaand say when a schema counts as Prisma's.How it was checked
prismaliterally, so changing the name back fails it;prismawhen both schemas have a ledger;prismaschema without Prisma's ledger falls back toprisma_contract, against a real database and in the navigation check;prisma_contractstill reads from it.tsc --noEmiton the project, and ESLint and Prettier on the touched files pass.prisma(withsignatures,ledgerandcontract), and the Migrations view lists all 20 seeded migrations and draws the before-and-after diagram, with no console errors.Release order
Release this Studio patch before Prisma ORM 8.0. Until it is out, Studio's Migrations view is empty for a database 8.0 has migrated. Console reads the same tables through Studio, so it moves to this release too.
Alternatives considered
_prismaas a third fallback. Rejected: only preview builds created it, and each fallback is code Studio carries until it is removed.prismaas Prisma's whenever it has a table namedledger. Rejected: an application's ownledgertable, a common name, would hide the history.Agent: laozi-26
🤖 Generated with Claude Code