Repository navigation
TML-3789: On PostgreSQL, Json(storage: jsonb) gives a jsonb column, Json still gives json, and sql.String(n) is now sql.Varchar(n) - #31065
Conversation
…PostgreSQL and the other targets Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…decs it lacks Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…here shared codec code goes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… for every target Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…chitect and principal engineer design reviews Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… scalar convenience types ADR Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… PlainJson, a json column, by default, or Jsonb A bare Json still gives pg/json@1, so no schema or contract changes. The json type's explicit name is PlainJson, the tools write a jsonb column as Json(storage: jsonb), jsonColumn is renamed plainJsonColumn with an upgrade instruction, and ADR 316, ADR 257 and ADR 279 record the naming rule and its PlainJson exception. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… every SQL target, and sql.String stays as a deprecated alias that warns in PSL Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…eSQL now and on the other targets when they get these convenience types, and define PlainJson as the explicit type a bare Json becomes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…index on a json column, and the upgrade detections find re-exported, namespaced and multi-line uses Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@prisma/orm-extension-arktype-json
@prisma/orm-extension-middleware-cache
@prisma/orm-extension-paradedb
@prisma/orm-extension-pgvector
@prisma/orm-extension-postgis
@prisma/orm-extension-supabase
@prisma/orm-family-mongo
@prisma/orm-family-sql
@prisma/orm-framework
@prisma/orm-mariadb
@prisma/orm-mongo
@prisma/orm-mysql
@prisma/orm-postgres
@prisma/orm-postgres-contrib
@prisma/orm-sqlite
@prisma/orm-target-mariadb
@prisma/orm-target-mongo
@prisma/orm-target-mysql
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
size-limit report 📦
|
…, Boolean, Bytes and Json as convenience types, and Int64 is now Int64BigInt (prisma#31067) ```prisma model Event { id ObjectId @id @Map("_id") visits Int // exactly Int32 total BigInt // exactly Int64BigInt, read as a bigint count BigInt(as: number) // exactly Int64Number, read as a number price Decimal // exactly Decimal128 name String // exactly BsonString payload Json // exactly PlainJson } ``` ## What changes for a user **MongoDB gets the eight scalar convenience types PostgreSQL has.** Each chooses one explicit type, and the contract stores only that explicit type. | Convenience type | `as` | `storage` | Becomes | Codec | | --- | --- | --- | --- | --- | | `Int` | | `int` | `Int32` | `mongo/int32@1` | | `BigInt` | `bigint` (default) | `long` | `Int64BigInt` | `mongo/int64@1` | | | `number` | `long` | `Int64Number` | `mongo/int64Number@1` | | `Float` | | `double` | `Double` | `mongo/double@1` | | `Decimal` | | `decimal` | `Decimal128` | `mongo/decimal128@1` | | `Boolean` | | `bool` | `Bool` | `mongo/bool@1` | | `Bytes` | | `binData` | `Binary` | `mongo/binary@1` | | `String` | | `string` | `BsonString` | `mongo/string@1` | | `Json` | | `bson` | `PlainJson` | `mongo/json@1` | - **No contract changes.** `pnpm fixtures:check` shows no difference. A schema written with the convenience types and one written with the explicit types emit byte-identical contracts. - **`Int`, `Float` and `Boolean` no longer warn.** They were deprecated aliases of `Int32`, `Double` and `Bool`. They are now the names a user is meant to write. - **Three explicit types are renamed,** because a convenience type and an explicit type cannot share a name: - `Int64` is now `Int64BigInt`. In PSL, `Int64` stays for one release line as a deprecated alias that warns and emits the same contract. In a TypeScript contract, `type.Int64()` is removed: it fails to compile, and from untyped code it throws an error that says to write `type.Int64BigInt()`. - The explicit `String` is now `BsonString` and the explicit `Json` is now `PlainJson`. A schema that writes `String` or `Json` is unaffected: the convenience types give the same codecs. - **The deprecation warning fires wherever a deprecated name is written:** with or without parentheses, in a field, a value object member, or the base of a `types {}` alias. Before, it fired only for a bare name in a field. This matches the SQL family. - **A mistyped type name** gets a message that lists the names a user is meant to write, convenience types first. - `storage: bson` on `Json` means "whichever BSON value fits". It is not the explicit type `Bson`, which accepts any BSON value. Upgrade instructions with detection patterns are in `upgrade-instructions/pending/mongodb-scalar-convenience-types/`. ## Why A convenience name must mean the same concept on every target. PostgreSQL got these eight in prisma#30942 and prisma#31065; this is the same design on MongoDB, declared with the existing type-choice mechanism. Nothing under `packages/1-framework` changes except one test's expected values. ## ADRs - **ADR 322 (new):** each target declares the scalar convenience types over its own explicit types. It records the rules shared by every target and MongoDB's table. SQLite's and MySQL's tables are added when those targets get the types. - ADR 257, ADR 279 and ADR 316 are amended to match. ## Verification - `/drive-code-review` (system design and code passes), two rounds. The second found two documentation gaps, fixed in the last commit; every acceptance criterion that applies to MongoDB passes. - Manual QA with the real CLI against a local MongoDB: emit, refusals, deprecation warnings, a TypeScript contract, `db init`, a write and read of every type with the stored BSON types checked, `db verify`, and the three MongoDB examples. ## Notes for the reviewer - The MongoDB deprecation warner is a second copy of the SQL family's (`deprecated-type-names.ts` in each interpreter). A shared home would be the framework, which this project does not change. A follow-up is recorded in the plan. - When `type.Int64()` fails to compile, TypeScript suggests `Int`, which is the 32-bit type. The runtime error and the upgrade instruction name the right replacement. - The examples now write `Int` and `Float` where they wrote `Int32` and `Double`. Their contracts are unchanged. ## Alternatives considered - **Keep `type.Int64()` as a deprecated TypeScript helper,** as the SQL builder does for its deprecated names. The MongoDB builder gives a deprecated name no helper (ADR 257). A TypeScript rename fails at compile time, and the upgrade instruction fixes it. - **Leave `Int64` unsuffixed.** BSON's `long` has two codecs, so both carry the value they read, as PostgreSQL's `Int8BigInt` and `Int8Number` do. - **A JSON string storage for `Json`.** It needs a new codec and is not part of this change. Part of TML-3790 (SQLite and MySQL follow in their own pull requests). Agent: genghis-36 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * MongoDB schemas now support scalar convenience types such as `Int`, `BigInt`, `Float`, `Decimal`, `Boolean`, `Bytes`, `String`, and `Json`, with options for choosing storage and value representation. * Explicit scalar names now include `Int64BigInt`, `BsonString`, and `PlainJson`. `Int64` remains available as a deprecated alias for `Int64BigInt`. * **Documentation** * Added upgrade guidance for MongoDB scalar names and TypeScript helpers. The TypeScript `type.Int64()` helper is no longer available. * Clarified how convenience types map to explicit types and BSON storage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
This closes the project that made `Int`, `BigInt`, `Float`, `Decimal`,
`String`, `Boolean`, `Bytes` and `Json` convenience types on every
target:
```prisma
model Product {
id Int @id
price Decimal(precision: 10, scale: 2)
stock BigInt(as: number)
data Json
}
```
The same model now emits on PostgreSQL, MongoDB, SQLite, MySQL and
MariaDB. All five slices are merged. This pull request changes no code.
It has three commits:
1. The measurements of MySQL 8.4 and MariaDB 10.11 that the MySQL types
rest on move from the project spec to
`docs/reference/mysql-mariadb-scalar-column-behaviour.md`, linked from
ADR 322 and the docs index.
2. The final retro goes into `drive/retro/README.md`, and two checks it
produced go into `drive/calibration/dod.md`.
3. `projects/scalar-convenience-types/` is deleted.
Refs TML-3715.
## Slices
| Slice | Pull request |
| --- | --- |
| PostgreSQL `Int`, `BigInt`, `Float`, `Decimal`, `String`, `Boolean`,
`Bytes` | prisma#30942 |
| PostgreSQL `Json`, and `sql.Varchar` | prisma#31065 |
| MongoDB | prisma#31067 |
| SQLite | prisma#31086 |
| MySQL and MariaDB | prisma#31109 |
Every review thread on all five is resolved (1, 0, 3, 3 and 8 threads).
## Acceptance criteria
| Criterion | Result | Evidence |
| --- | --- | --- |
| Each row of each target's table resolves to its explicit type in PSL
and in a TypeScript contract | Met | `scalar-convenience-types.test.ts`
in the PostgreSQL, SQLite and MySQL target packages and in the SQLite
and MongoDB facades; `convenience-scalar-types.test.ts` in the MySQL
facade; `interpreter.type-choices.test.ts` in the MongoDB PSL package |
| A schema written with convenience types and one written with explicit
types emit the same `contract.json` | Met | The same test files compare
the two emitted contracts |
| Existing fixtures and examples emit byte-identical `contract.json`,
except SQLite `Decimal` and `BigIntNumber` | Met | `pnpm fixtures:check`
passed in every slice's CI and on the last branch after merging `main`;
the SQLite exceptions have an upgrade instruction and a CLI journey test
|
| PostgreSQL `contract infer` and `contract print` write the convenience
calls; other targets test each explicit type's convenience call | Met |
`psl-print/convenience-types.test.ts`,
`type-choice-inferred-marks.test.ts`, the print round-trip tests in the
merge queue; the per-target test files above |
| Each removed explicit name is a deprecated alias that warns, except
SQLite `BigIntNumber`; MongoDB `Int`, `Float`, `Boolean` no longer warn
| Met | `interpreter.deprecated-type-names.test.ts` (SQL) and the
MongoDB interpreter's deprecation tests |
| PostgreSQL `Json` behaves as specified | Met | prisma#31065:
`scalar-convenience-type-helpers.test.ts`, the infer and Prisma 7 reader
tests |
| Each stated limit of `json` is checked before it is documented | Met |
prisma#31065 |
| `check:upgrade-coverage`, `lint:ratchets` and `lint:deps` pass in
every slice | Met | CI on each slice; run again on this branch |
| Every rename a user must act on has an upgrade instruction with a
detection pattern | Met |
`upgrade-instructions/pending/postgres-json-convenience-type`,
`mongodb-scalar-convenience-types`, `sqlite-scalar-convenience-types`,
`mysql-scalar-convenience-types`, each with a `detection.test.ts` |
| `docs/reference/scalar-types.md` and the ADRs describe the final names
| Met | ADR 316, ADR 322, ADR 257, ADR 314 |
| No source file under `packages/1-framework` changes | Met | No slice
changed a file under `packages/1-framework/**/src/` |
One row of the MySQL table was deferred with a ticket: `Float(storage:
float)`, because a `float` column reads back rounded to six significant
digits.
## Where the spec's decisions live
The spec had decision sections. Each decision is in an ADR:
| Decision | Home |
| --- | --- |
| The shared rules for convenience and explicit names, and the
exceptions (`PlainJson`, `BsonString`, `IntegerBoolean`) | ADR 316, ADR
322, ADR 257 |
| PostgreSQL `Json` keeps meaning a `json` column; `sql.String` becomes
`sql.Varchar` | ADR 316 |
| MongoDB's table; `Int`, `Float`, `Boolean` stop warning | ADR 322, ADR
257 |
| SQLite's table; `Decimal` and `Boolean` get their own data types; the
driver reads every integer exactly | ADR 322 |
| The nine MySQL decisions (decimal parameters are cast, `Float` is
`double` only, `Bool` refuses values other than 0 and 1, `Json` has no
equality, MariaDB's JSON is read from its check, expression defaults,
decimals read as printed, bytes as base64 in an include, `binary`
defaults kept as reported) | ADR 322, MySQL section |
| Value logic shared by targets lives in
`@internal/type-implementations` | ADR 314 |
| The measurements behind the MySQL decisions |
`docs/reference/mysql-mariadb-scalar-column-behaviour.md` (this pull
request) |
## Files in the project folder
| File | Classification |
| --- | --- |
| `spec.md` | Transient, deleted. Its decisions are mapped above; its
measurements are migrated, with the sentences that described the code
before the change removed. |
| `plan.md` | Transient, deleted. |
No file outside the folder referred to it, before or after.
## Follow-ups
- TML-3898: the deprecated-name warner exists in both the SQL and
MongoDB PSL interpreters. One copy needs a framework change.
- TML-3892: `Decimal(precision: 10)` without a `scale` is refused on
MySQL and means scale 0 on PostgreSQL.
- TML-3896, the list of what MySQL and MariaDB need beyond a proof of
concept, gains the gaps found in the MySQL slice. It already held the
missing `Float(storage: float)` and the late failure of keys on `Bytes`,
`Json` and text columns.
- TML-3887, error messages in internal terms, gains two instances: a
refused write names the codec and not the field, and an include's decode
error is wrapped twice.
- TML-3833 (clearer errors where a PostgreSQL `json` field hits a limit)
and TML-3778 (PostgreSQL and SQLite `Json` codecs accept a value that is
not plain JSON) were filed earlier.
## Checked on this branch
`pnpm lint:docs` and `pnpm check:upgrade-coverage --mode pr` pass. `pnpm
build`, `pnpm typecheck`, `pnpm fixtures:check`, `pnpm lint:ratchets`
and `pnpm lint:deps` passed on the last slice after merging `main`, and
this branch adds only Markdown to that commit.
Agent: genghis-36
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Documentation**
* Added measured reference material on scalar-column behavior in MySQL
8.4 and MariaDB 10.11, covering reads, writes, defaults, metadata,
comparisons, JSON, aggregates, and server differences.
* Updated database and architecture references to link to the
measurements; the guide notes that its Prisma ORM mapping recollection
was not verified against documentation.
* Clarified validation checklists for package coverage, confirming
checks match the latest commit, and searching for affected integration
tests when message text changes.
* Added a retrospective entry covering merge-queue timing, testing,
coverage, recorded rulings, ticket scope, and review lessons.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
What changes for a user
Jsonis a convenience type on PostgreSQL. It has one option,storage:JsonorJson(storage: json)PlainJsonjsonJson(storage: jsonb)JsonbjsonbJsonkeeps itsjsoncolumn.pnpm fixtures:checkshows no difference.contract inferandcontract printwrite ajsoncolumn asJsonand ajsonbcolumn asJson(storage: jsonb). They wroteJsonbbefore.Jsonbremains valid.Json, which wasjsonb, asJson(storage: jsonb), andJson @db.JsonasJson.type.Json()andtype.Json({ storage: 'jsonb' })are typed as the explicit type they choose. The column helperjsonColumnis renamedplainJsonColumn, with no alias.jsoncolumn cannot do (equality filters, indexes, unique constraints) and thatJson(storage: jsonb)can. A new integration test shows the index and unique limits against PostgreSQL.sql.String(n)is renamedsql.Varchar(n)on PostgreSQL, SQLite and MySQL.sql.Stringstays for one release line as a deprecated alias: in PSL it warnsPSL_DEPRECATED_SCALAR_NAMEand emits the same contract; in TypeScript it still compiles.Both renames have upgrade instructions with detection patterns in
upgrade-instructions/pending/postgres-json-convenience-type/.Why
Jsondefaults tojson.Jsonis the exact name of a PostgreSQL type, so it must not mean a different one. A user who wantsjsonbsays so.PlainJsonexists because a convenience type and an explicit type cannot share a name. A type choice names its explicit type in the same namespace. Users meetPlainJsonin hover text, the type reference, and the refusal of@db.Json. The tools never write it.sql.Stringshared a name with theStringconvenience type and meant something else (avarchar(n)column). The namespace is nowsql.Varchar(n)andsql.Char(n).ADRs
Json, the rule for naming an explicit type whose natural name is a convenience name, the reasonBigIntis kept as its own concept, and thesql.Varcharrename. ADR 257 and ADR 279 are amended to match.f1f5d2a83b). ADR 320 is taken by TML-3727: A database records whether db update may move it, and db migrate, db update and db sign obey it #30926.Also in this pull request
projects/scalar-convenience-types/spec.mdandplan.mdhold the design for the rest of the project: the same eight convenience types on MongoDB, SQLite and MySQL, each in a later pull request.Verification
/drive-code-review(system design and code passes), two rounds; the second is clean on the pushed tip, with all acceptance criteria for this change passing.db init,contract infer,contract printround-trip,db verify, a TypeScript contract, and the Prisma 7 reader.packages/1-frameworkchanges.Known gaps, tracked separately
Json @uniqueor an index on aJsonfield fails only when the migration runs, with PostgreSQL's own message, which does not mentionJson(storage: jsonb). TML-3833 covers a clear error.jsonbColumnfor the removedjsonColumn. The upgrade instruction names the right replacement.Alternatives considered
Jsontojsonb. Built in TML-3789: PostgreSQL Json stores jsonb by default, and Json(storage: json) keeps a json column #30966 and closed: it changed every existingJsoncolumn and made a PostgreSQL type name mean another type.Json. Leaves no way to say "a JSON value" and choose its storage, which every other scalar now has.JsonJson, by the value-suffix rule. It says nothing.sql.Stringinside the SQLite pull request. PostgreSQL is the released target it affects, so it ships here.Closes TML-3789.
Agent: genghis-36
Summary by CodeRabbit
New Features
Jsonnow supportsjsonstorage by default andjsonbvia an explicit storage option. The explicitjsontype is namedPlainJson.sql.Varchar;sql.Stringremains available as a deprecated alias.plainJsonColumn.Documentation
json.