GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
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
|
| 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.
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.
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".
Paths are from the repository root.
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.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.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.
@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.
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.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.
_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._prisma and retry against prisma_contract on an error. Rejected: Studio already knows which tables exist, and an error can mean something else.Agent: laozi-26
🤖 Generated with Claude Code
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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]>
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]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Compute preview deployed with Prisma Composer. Stage: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.