Skip to content

Shape the intent-hints project: the planner refuses destructive changes unless the schema states the intent - #30557

Draft
wmadden-electric wants to merge 9 commits into
mainfrom
tml-3421-rename-hints
Draft

wmadden-electric wants to merge 9 commits into
mainfrom
tml-3421-rename-hints

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

At a glance

A user renames the Profile model to User, renames its first_name column, and removes the Legacy model for good, and says all three in the schema:

model User {
  id        Int    @id
  firstName String @hint(was: "first_name")

  @@hint(was: "Profile")
}

model Legacy {
  @@hint(deleted: true)
}

After this project, prisma migration plan writes a migration that renames the table, the column, and every constraint and index named after them, and drops Legacy. prisma db update does the same against a live database. Without the deleted hint, both commands refuse to drop Legacy. Once an environment is updated the hints match nothing and do nothing, so the user may delete them whenever they like.

Today the rename plans as a drop and a create, and the rows are gone. The only route is a hand-written migration, and only for tables. The drop is planned and relies on a consent prompt in db update, and on nothing at all in migration plan.

What this PR changes

This PR adds no code. It lands the shaping artifacts for the project under projects/intent-hints/:

  • spec.md: purpose, the decisions settled in design discussion, cross-cutting requirements, project definition of done.
  • plan.md: four stacked slices with their Linear issues.
  • design-notes.md: the reasoning behind each decision, the recovered design the project builds on and its verification against today's code, and the alternatives rejected.
  • README.md: the index.

Why intent, not inference

The migration planner diffs two states: the destination contract and an origin schema, which is a contract snapshot for migration plan and an introspected database for db update. A renamed model looks exactly like a dropped table plus a created one, and a removed model looks the same as one the user forgot. The planner refuses to guess, because two unrelated tables can share columns and a wrong guess carries rows into the wrong table.

The subsystem docs have described @hint(was: "old_name") as the answer since the first ADRs, and a design document deleted before the release candidates, "Contract-Driven DB Update", went further: db update as a safe path on any environment, with destructive operations refused by default and an active, deprecated, deleted lifecycle stated in the authoring layer. The recent rename-table work (#30331) added the operation and a this.renameTable(...) call for hand-written migrations, and left the hint as the follow-up. This project builds the mechanism from that recovered design, verified against the code as it is now.

The decisions

The spec records these; the design notes record why.

  • The planner refuses destructive operations by default. db update already does, through its consent prompt. migration plan gains the same refusal, so an ordinary plan never writes a drop the user has not stated. Command-level consent stays as the fallback for a change no hint can express.
  • Hints state the intent, in the contract source. One attribute with named arguments: was for a rename, deleted for a confirmed removal, and deprecated reserved for an object the application no longer needs but the database may keep. Hints that supply an expression, such as a cast for a type change, are declared future arguments of the same attribute and not built here.
  • was holds the old storage name, what @@map or @map would have said. The planner resolves it against the origin schema alone and never opens an older contract, so the contract stays self-contained and the hint works for db update, which has no older contract to consult.
  • A spent hint is silently ignored. Projects without migration history plan live on every environment, so a hint must be safe to leave in place until the last environment is updated.
  • A deleted model is a tombstone. The block stays in the schema, because a drop is absence and absence cannot carry an attribute. It contributes nothing to the contract but its hints entry.
  • Hints travel in contract.json outside the hashed sections and are stripped from snapshots and migration directories. The storage hash of a contract with and without hints is identical.
  • Surfaces and targets. PSL and TypeScript authoring; Postgres and SQLite. MongoDB, deprecated, namespace moves, enum value renames and named-index renames are follow-ons. The documented dev-only stance on db update is left alone.

The slices

  1. The attribute, the contract section and model renames, reusing the rename-table work. Lands after TML-3420: rename a table without losing its rows, stated with this.renameTable in a hand-written migration #30331 merges.
  2. Field renames, including a new column rename operation on both targets and renames of the indexes whose content-hashed names change with the column.
  3. migration plan refuses destructive operations by default, with the same consent model as db update, and both refusals name the hint that would state the intent.
  4. deleted on models and fields.

Alternatives considered

  • Have was name the old model rather than the old table. Rejected because resolving it requires the previous contract, which db update does not have, and the contract must be self-contained.
  • The recovered design's environment history check, which drops an object only if the environment's marker contract already did not require it. Rejected because it needs marker contract storage, off by default, and is the "open an older contract" the self-containment rule forbids. A tombstone says what to drop; the environment's own schema says whether it is still there.
  • One-phase drop as the whole removal story. Rejected because a rolling deploy may still have the old app version reading a column when the new contract drops it. The two-phase vocabulary is adopted whole now so nothing is renamed later.
  • Warn on a hint that matches nothing. Rejected because db update users would see the warning forever and learn to delete hints early, which is the data-loss case.
  • A sibling hints file next to contract.json. Rejected as a second artifact every emitter and copy step must carry.
  • Re-read the schema source at plan time. Rejected because tooling runs on canonical JSON only, and TypeScript authoring has no source file to re-read.

Refs: TML-3421

Agent: scylla-59

🤖 Generated with Claude Code

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner October 1, 2026 07:08
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (5)
  • projects/intent-hints/README.md is excluded by !projects/**
  • projects/intent-hints/design-notes.md is excluded by !projects/**
  • projects/intent-hints/design.md is excluded by !projects/**
  • projects/intent-hints/plan.md is excluded by !projects/**
  • projects/intent-hints/spec.md is excluded by !projects/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Repository: prisma/orm/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: deb6370c-f150-4f79-8576-61c4266138ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30557

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30557

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30557

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30557

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30557

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30557

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30557

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30557

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30557

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30557

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30557

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30557

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30557

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30557

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30557

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30557

commit: ce43df9

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 213.96 KB (0%)
postgres / emit 192.07 KB (0%)
mongo / no-emit 195.73 KB (0%)
mongo / emit 174.98 KB (0%)
cf-worker / no-emit 269.89 KB (0%)
cf-worker / emit 245.23 KB (0%)

… not only renames

Rename the folder to projects/intent-hints, adopt the deprecated/deleted
lifecycle vocabulary from the recovered Contract-Driven DB Update design,
add the migration plan refusal and the deleted tombstone as slices, and
record the verification of that design against today's code.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@wmadden-electric wmadden-electric changed the title Shape the rename-hints project: a hint in the schema tells the planner a model or field was renamed Shape the intent-hints project: the planner refuses destructive changes unless the schema states the intent Oct 1, 2026
wmadden-electric and others added 7 commits October 1, 2026 13:14
Numbered rules for the attribute grammar, the contract section, resolution
against the origin, rename application in the planners, stated drops,
consent in migration plan, reporting, tests and docs, after one review
pass against the code.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…tion

Combined table-and-column renames fold into one renameTable call with a
columns map; stripOperations keeps statedIntent and target; toOps takes
the lowerer; consumed-hint text is rendered where the family instance is
available; advice keys on the op id prefix; stated-drop closure reads the
adjusted origin; the consistency check becomes a family capability;
ownership gains ownerOf; corrected class, facade, file and union names.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
… names, index drops are widening, ignored hints warn

Four operator rulings: no composite rename call, a working schema that
each facade call advances instead; constraint companion names come from
the destination contract and the origin's actual name; DropIndexCall is
widening on both targets; a hint on a table control policy protects is
ignored with a warning and the old table's drop goes through consent.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ts, checks and policies are widening

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@wmadden-electric

Copy link
Copy Markdown
Contributor Author

Shelved on 2026-10-05. After discussion with Serhii, stating planner intent through the contract source (@@hint(was:)) was judged unintuitive. The next attempt will state the intent through the CLI commands instead; the design restarts from the start. The branch stays in place because the planner substrate (working schema shared by planner and facade, destination-driven constraint names, the destructive-means-data-loss classification) is reusable.

Yumihariii pushed a commit to Yumihariii/orm that referenced this pull request Oct 8, 2026
… with --rename, instead of dropping it (prisma#30638)

## At a glance

A user renames the `Profile` model to `User` and its `name` field to
`fullName` in the contract source, then says so on the command line:

```text
$ prisma migration plan --name tidy --rename Profile:User --rename User.name:User.fullName
✔ Planned 6 operation(s)

migrations/app/20261007T1003_tidy
├─ Rename table "Profile" to "User"
├─ Rename primary key "Profile_pkey" to "User_pkey" on "User"
├─ Rename index "Profile_handle_idx_b5b249e4" to "User_handle_idx_b5b249e4" on "User"
├─ Rename column "User"."name" to "fullName"
├─ Rename unique constraint "Profile_name_key" to "User_fullName_key" on "User"
└─ Rename index "Profile_name_handle_idx_f7a67607" to "User_fullName_handle_idx_46490beb" on "User"

Statements applied
├─ rename model "Profile" to "User" (3 operations)
└─ rename field "User.name" to "User.fullName" (3 operations)
```

The written `migration.ts` holds `...this.renameTable(...)` and
`...this.renameColumn(...)`, the calls a user could write by hand, and
re-running it writes the same `ops.json`. `prisma db update` takes the
same statements and does the same to a live database, with no consent
prompt. Before this change the same edit planned `dropTable "Profile"`
plus `createTable "User"`, and the rows were gone after one consent
prompt.

## The decision

The user states a rename on `migration plan` and `db update` as
`--rename <old>:<new>`, naming models and fields as the contract source
names them. The planner acts on the statement and never guesses: a
change with no statement is planned as the diff shows it.

- **Resolution in the framework, storage in the family.** The CLI parses
each statement and resolves it against the origin contract and the
destination contract into domain coordinates (namespace, model, field).
The SQL family maps each resolved statement to a storage effect (a table
rename, a column rename, or nothing when storage did not change) and
applies it, in order, to a working copy of the origin schema. The
Postgres and SQLite planners emit the rename, then rename every
constraint and index named after the old table or column to the name the
destination contract gives it, then run the usual diff on the renamed
schema.
- **An unusable statement is an error, and nothing is written.**
`MIGRATION.STATEMENT_INVALID` (syntax), `MIGRATION.STATEMENT_UNRESOLVED`
(the names do not match the two contracts) and
`MIGRATION.STATEMENT_ORIGIN_UNKNOWN` (no origin contract) each say what
was searched, what was found, and the statement to type instead. A
statement the planner cannot carry out is a `statementRefused` conflict
under `MIGRATION.PLANNING_FAILED`, carrying the statement as
`refusedStatement`.
- **`db update` finds the old contract through the snapshot of its
marker hash**, and only when statements are given; without them nothing
changes. Running the same statements twice fails the second time and
says the rename already happened.
- **The plan reports what each statement did.** The planner result
carries `appliedStatements`, one per statement, each with the resolved
statement and the positions of the operations it produced in the plan.
Both commands print them under `Statements applied` and in `--json`.
- **Drops that lose no data are widening.** Dropping an index, a unique
or foreign-key constraint, a check, a row-level-security policy, a
default or a native enum type, and disabling row-level security, no
longer need consent on Postgres and SQLite. A SQLite rename rebuilds
indexes, and would otherwise always ask.
- **MongoDB refuses statements in this release.** Before this change it
would have accepted `--rename` and planned a drop and create. The
refusal says how to keep the documents by hand.

## How it fits together

- `packages/1-framework/3-tooling/cli/src/control-api/statements/` —
parse and resolve statements. The control API takes one ordered list of
`{ verb, text }`, so later verbs and an interactive prompt feed the same
entry point.
-
`packages/1-framework/1-core/framework-components/src/control/migration-statements.ts`
— `ResolvedMigrationStatement`, `AppliedMigrationStatement`,
`describeMigrationStatement`. The planner options gain `statements` and
`origin`; the success result gains `appliedStatements`.
- `packages/2-sql/9-family/src/core/migrations/statement-planning.ts` —
storage effects and the ordered application against a target's working
schema.
- `packages/3-targets/3-targets/{postgres,sqlite}/src/core/migrations/`
— `working-schema.ts`, `renameColumn` (new, beside `renameTable`),
companion constraint and index renames, planner wiring. The working
schema and destination-driven companion names come from the shelved
prisma#30570, without its contract-source hints.
- `packages/1-framework/3-tooling/migration/src/aggregate/` — only the
application space receives the origin contract and statements.
- Identifiers: the shared Postgres and SQLite `qualifyTable` helpers now
escape `"` in names. Review found that a table name containing a quote
reached rename SQL unescaped through a statement; the probe and the fix
are in the hostile-name tests on PGlite and `node:sqlite`.

## What this does not do yet

`--delete` and the refusal of data loss by default (the next slice),
`--convert` and `--backfill`, renames of namespaces, enum values and
value-object fields, a model moved to another namespace (refused), a
model that keeps its name but changes `@@map` (refused, with the
hand-written route), and statements on MongoDB.

## Verification

- Journeys on Postgres and SQLite:
`test/integration/test/cli-journeys/rename-statements-migration.e2e.test.ts`
and `.sqlite.e2e.test.ts` rename a model and a field through `migration
plan` + `db migrate` and through `db update`, on tables with rows, a
unique, a foreign key from another table, a secondary index, and on
Postgres a check and a policy. They assert the database state directly,
that a further plan is empty, that `db verify --schema-only` is clean,
that re-running `migration.ts` is byte-identical, and that a second `db
update` with the same statements fails.
- A manual QA run against real databases (Postgres through
`@prisma/dev`, SQLite, MongoDB) covered ten scenarios; its findings are
fixed and the commands re-run.
- Upgrade instructions for both audiences are in
`upgrade-instructions/pending/migration-statement-renames/`.

## Alternatives considered

- **Intent in the contract source** (`@@hint(was:)`, prisma#30557
and prisma#30570). Shelved as unintuitive; it also had to survive
until every environment consumed it.
- **Detecting renames, or asking in a prompt whether a drop is a
rename.** Rejected: detection guesses, and a prompt cannot be answered
by a script or an agent. A prompt that asks the user to state the
intent, without guessing, is the planned next step on top of this entry
point.
- **Storage names on the command line** (`--rename-table`). Rejected:
the command line speaks the contract's vocabulary, and the same
statement must mean the same thing on every family.
- **Putting the schema into Postgres operation ids** so a statement
could point at its operations by id. Rejected during review: the ledger
keeps each migration's hash, and re-emitting an existing migration with
new ids would drop its applied mark. Statements point at operations by
position instead.

Refs: TML-3475

Agent: turing-38


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added repeatable `--rename old:new` options to `migration plan` and
`db update` for model and field renames. PostgreSQL and SQLite plans can
include corresponding table, column, and related-object renames.
* Plans and update results now report applied rename statements and
their associated operations.
* Added validation and actionable errors for invalid, unresolved, or
unsupported rename statements. MongoDB plans report rename statements
they cannot apply.
* **Behavior Changes**
* Drops of non-data-bearing objects and disabling row-level security are
classified as widening operations on SQL targets.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant