Repository navigation
TML-3296: sql is the tag of the SQL family's data type sql/expression - #30534
Conversation
Spec, design, plan, decisions, research and the status file for resuming the work. Raw SQL in a schema is a value of the data type sql/expression. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…d literal printer Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…emoved Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…odes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…type slice Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…on data type slice Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…stack Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The cast rule already keeps the sql/expression entry out of literal defaults. Also corrects the wrapNamespaceBlock line reference in the design (F09). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The code now reports only a single value written on a list column, which is a refusal about shape, not about type. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
A cast and a list cast that throw are PSL_INVALID_LITERAL. Every refusal row now asserts its whole message. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
It reads the canonical value through sqlTextFromCanonical, as the six places in slice 2b will. The reserved-name message names the tag through SQL_EXPRESSION_TAG. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…s user lowerTaggedLiteral lowered nothing any more, and its refusal had the type of a default-function result. The sql/expression code moves out of data-type-default.ts, which holds no per-type code. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The sqlExpressionDataType doc comment points at ADR 254. sqlTextReadsBack moves to slice 2b, next to its caller. The authoring entry exports only printTaggedLiteral from tagged-literal; each other function is added in the slice that first imports it from there. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The code comment, the entry documentation the editor shows, and ADR 254 said "SQL text", which would admit a statement or a query. The extensions doc no longer teaches a view query as a sql literal or describes the removed prefixed tags. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…nd text ADR 129 is retitled "Tagged literals write values of data types" and no longer says a tag names the pack that owns the text. ADR 254 states the prefix rule once, by the owner of the data type, and ADR 129 and the index link to it. The body is what is written between the quotes; the text is the canonical value. ADR 254 now says @default reports its cast-rule codes at the attribute. The error reference drops "a list holding another list", which PSL cannot write. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
They used pg.sql and sqlite.sql, which no longer exist, as the example of a valid dotted tag. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
assertNothingCastsFromSqlExpression throws CONTRACT.DATA_TYPE_CASTS_FROM_SQL_EXPRESSION for a cast or a list cast from sql/expression. The family instance runs it on every data type the stack registers, so an extension cannot turn a sql literal into a value of another type. runtimeError is exported from the shared codec entry so shared-plane code can raise the same kind of error as stack assembly. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
For Postgres with every shipped extension pack, and for SQLite: the stack registers the family objects themselves, and no registered data type casts from sql/expression. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Deleting the adapter authoring tests removed the only tests of the Postgres and SQLite number classifiers, the boolean reader, and JSON and numeric read and print. The cases move to the targets, which own the entries; only the cases about lowering keys are dropped. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ql/expression cast error names the contributor ControlStack exposes declaredDataTypes, the list assembleDataTypes builds, with the id of the component that registered each type. assertNothingCastsFromSqlExpression takes that list and puts contributedBy in its message and payload, like the other CONTRACT.DATA_TYPE_* errors. createSqlFamilyInstance and the registration test use the list instead of walking the descriptors. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The Assembly section now says a family may add checks for its own data types, and that the SQL family runs its check when it creates its control instance, so the CLI reports it and the language server does not. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…hared components entry runtimeError, isRuntimeError and RuntimeErrorEnvelope are exported from @internal/framework-components/components instead of runtimeError alone from /codec. sql-expression.ts imports runtimeError from there. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…tag at the literal The json entry documentation on Postgres and SQLite, its test copies, ADR 254 and the codec authoring guide say "Reads the text", not "the body". ADR 254 says @default reports PSL_UNKNOWN_LITERAL_TAG at the literal and the other codes at the attribute; the slice 2t carry-over in plan.md no longer lists that code. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ression The spec says the SQL family registers sql/expression and its entry, and the targets do not. The extension fragment names CONTRACT.DATA_TYPE_ENTRY_DUPLICATE, which a target that also registers the entry sees first. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…erun the manual QA The registration test checks that the sql/expression entry comes first on Postgres and SQLite, so users see sql before json. The manual QA run on the tip replaces the run that predated the family registration; status.md no longer says that run matched. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ypes createSqlFamilyInstance reads stack.declaredDataTypes, so the hand-built stack in the operation preview test needs the field. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… status of the fixes Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… locally; CI runs the full suite Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: prisma/orm/.coderabbit.yml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (29)
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change registers ChangesSQL expressions as typed values
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PslColumnResolution
participant ReadValue
participant SqlExpressionAuthoringEntry
participant StorageDefault
PslColumnResolution->>ReadValue: read tagged text
ReadValue->>SqlExpressionAuthoringEntry: parse text as sql/expression
SqlExpressionAuthoringEntry-->>ReadValue: return canonical SQL text
ReadValue-->>PslColumnResolution: return the typed value
PslColumnResolution->>StorageDefault: store validated text as a function default
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change moves the Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to SQL literals gain a consistent type and ownership model while retaining the reviewed default-expression validation. Public extension APIs change, and incomplete security coverage leaves some residual uncertainty. No introduced security defect was established in the inspected paths. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 45.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 40 functions across 48 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
@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-mongo
@prisma/orm-postgres
@prisma/orm-sqlite
@prisma/orm-target-mongo
@prisma/orm-target-postgres
@prisma/orm-target-sqlite
@prisma/orm-toolchain
commit: |
size-limit report 📦
|
…on-data-type Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # docs/reference/error-reference.md # packages/2-sql/9-family/test/psl-build/default-mapping.test.ts # packages/3-targets/3-targets/postgres/test/psl-infer/inferred-psl.round-trip.test.ts
… PSL_INVALID_LITERAL The tests added by TML-3302 expected PSL_INVALID_DEFAULT_LITERAL, the code before this branch renamed the refusals of an authoring entry or a cast to PSL_INVALID_LITERAL. PSL_INVALID_DEFAULT_LITERAL stays for a value the column's codec refuses. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
… is PSL_INVALID_LITERAL The three cases TML-3302 added expected PSL_INVALID_DEFAULT_LITERAL. On this branch a quoted date is read as text and the column type's cast from text throws, which is an unreadable refusal, reported as PSL_INVALID_LITERAL. PSL_INVALID_DEFAULT_LITERAL stays for a value the column's codec refuses. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…on-data-type Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # docs/reference/error-reference.md
This brings in seven main commits: the rc.14 release, Mongo values through their field's codecs (#30519), `sql` as the tag of sql/expression (#30534), view bodies parsed as fields only in Prisma 7 and 6 schemas (#30507), and three docs and CI changes. Both sides' rules hold after the merge. - Mongo codecs: main's encode checks and this branch's decodeJson readers are combined, and the int32 bounds use INT32_RANGE. - One test codec from main now has the decodeJson that mongoCodec requires. - contract-psl: main's tag reading and sql/expression default replace the lowering entry. This branch's stored-value reader, InternalError rethrows, list-column and value-object default checks, and CodecLookupWithDescriptors are kept. - A value-object default of the wrong shape uses main's renamed code, PSL_VALUE_TYPE_INCOMPATIBLE. A Uuid default the text-to-uuid cast refuses is PSL_INVALID_LITERAL, like any other cast refusal. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
) ## Linked issue Refs [TML-3367](https://linear.app/prisma-company/issue/TML-3367), the second slice of the Linear project [SQL expression literals](https://linear.app/prisma-company/project/sql-expression-literals-c8a6659e7f4c). Builds on #30534 (TML-3296) and targets its branch until that merges. The Linear project "Data types own column types" is waiting on this PR. ## Summary Prisma 8 decides whether a written value fits a column by data type: `"8"` is a `pg/text` value, `8` is a `pg/int2` value, and a column accepts a value only if its type is that type or casts from it. Until now only `@default` applied that rule, and the code for it lived in the SQL family. This PR moves the rule into the framework and packages it as `dataTypeValue`, an argument type any attribute or block can use to say "I receive a value of type X". Nothing uses it yet; the next slice gives index predicates, check constraints and policies the type `sql/expression`, and another project types default-function arguments such as the `8` in `nanoid(8)`. ## Skill update n/a. Schemas do not change. Three diagnostics move or reword, recorded in `upgrade-instructions/pending/arguments-typed-by-data-type/`: `@default` refusals point at the written value instead of the whole attribute, a call to a default function with wrong arguments reports what is wrong with the arguments instead of `Expected one of: …`, and a refused `@default` value says what to write instead of listing the column's casts. ## At a glance What a schema author sees. Before this PR, a wrong argument to a default function was reported at the whole value with a list of everything `@default` accepts: ```prisma model User { id String @id @default(nanoid("8")) // ^^^^^^^^^^^^ Expected one of: string | number | boolean | autoincrement() | … } ``` After this PR the argument itself is typed, so the report lands on `"8"` and says what to write: ```prisma model User { id String @id @default(nanoid("8")) // ^^^ pg/int4 has no cast from pg/text; write a number } ``` What the spec author writes to get that: one argument type in the attribute's spec, naming the data type the argument receives. ```ts funcCall('nanoid', { positional: [dataTypeValue(dataTypeId('pg/int4'), ctx.dataTypes)] }) ``` Given `nanoid(8)` it returns `{ type: 'pg/int4', value: 8, span }`. In the next slice the same argument type, with `sql/expression`, turns `where: "(archived_at IS NULL)"` into a message that ends with the exact rewrite: ``sql/expression has no cast from pg/text; write it as sql`(archived_at IS NULL)` ``. ## Decision This PR ships five things. 1. **The cast rule for a single written value is framework code.** `readWrittenValue` turns a literal into a typed value through the authoring entry registered for its syntax, and `castTypedValue` applies the [ADR 254](docs/architecture%20docs/adrs/ADR%20254%20-%20Data%20types%20and%20casts.md) cast rule. Both live in `packages/1-framework/1-core/framework-components/src/shared/written-value.ts`. The SQL family keeps only what is specific to `@default`: lists and the two default-only refusals. 2. **`dataTypeValue(dataType, support)` is an argument type** in the attribute-spec combinator kit ([ADR 231](docs/architecture%20docs/adrs/ADR%20231%20-%20Declarative%20attribute%20specifications.md)). The other combinators (`str()`, `int()`, `entityRef()`, `funcCall()`) describe PSL syntax, and their values are schema metadata such as an index name. `dataTypeValue` is for the positions whose value goes to the database: it reads any literal, types it by how it is written, runs the cast rule for the data type the position names, and returns the canonical value, its type id and the argument's span. Its refusals use the general diagnostic codes and point at the written value. 3. **The stack exposes its data types once, and every spec context carries them.** `ControlStack.dataTypes` and `ContractSourceContext.dataTypes` hold the registered data types together with their authoring entries; the old `dataTypeLookup` field is gone. Every place that builds an attribute spec context passes that pair ([ADR 249](docs/architecture%20docs/adrs/ADR%20249%20-%20Central%20attribute-spec%20registry.md)). 4. **One wording for a refused value.** A refusal is the structured reason a written value is not admitted (an unknown tag, text the entry cannot read, no cast from the value's type), before any command words it as a diagnostic; the code has `ReadRefusal` and `CastRefusal`, and ADR 254 says a value is "refused by the cast rule". `describeRefusal` in the framework turns a refusal into its code and message, and both `@default` and `dataTypeValue` use it. `@default(1.5)` on an integer column and, later, `nanoid(1.5)` say the same thing: `pg/int4 has no cast from pg/float8; write a number`. 5. **`oneOf` keeps the diagnostics of the function the author named.** When the argument is a call to a plain identifier and exactly one alternative is a `funcCall` of that name, `oneOf` returns that alternative's result as is. Without this, every function default's argument error would be swallowed by `Expected one of: …`. ## How it fits together 1. **A written value has a data type of its own.** ADR 254 gave every literal a type decided by how it is written: a quoted string is the target's text type, `true` its boolean type, a number the smallest numeric type that holds it, and a tagged literal such as `` json`{}` `` the type whose authoring entry owns the tag. A "written value" is the literal in that form, before any type is chosen. A "canonical value" is the JSON the type stores. 2. **A receiving position admits a value by the cast rule.** The receiving type takes the value if it is that type, or if it declares a cast from the value's type. `castTypedValue` runs the cast and returns a value of the receiving type. Nothing else decides admission; there is no per-syntax special case. 3. **`dataTypeValue` applies steps 1 and 2 to one attribute argument.** It reads the PSL expression as a written value (`readWrittenScalar`), types it (`readWrittenValue`), casts it (`castTypedValue`), and reports any refusal at the argument with a message that ends in what to write. Spec authors pass the data type id and the stack's data types; a stack that lacks the type still builds the spec, and only `parse` throws, so the language server can list attributes on any stack. 4. **Specs get the stack's data types from their context.** `AttributeSpecContext.dataTypes` is set by the SQL and Mongo interpreters, the binder and the language server, all from the one pair the control stack builds. `EMPTY_DATA_TYPES` is the explicit value for a language-server source with no stack. 5. **`@default` now speaks the same language.** It reads its scalar values through the framework functions and words its refusals through `describeRefusal`, so an author sees one message shape whether the value sits in `@default(...)` or in a typed argument. 6. **`oneOf` lets the argument's message through.** Every `@default` function is one alternative of a `oneOf`. When the author names a function that exactly one alternative offers, that alternative's diagnostics are the answer, not `Expected one of`. ## Reviewer notes - **Largest diff:** `packages/2-sql/2-authoring/contract-psl/src/data-type-default.ts` and `psl-column-resolution.ts`. Code moved out to the framework; what stayed is list handling, the default-only refusals, and the location prefix (`Field "X.y": `, `Field "X.y" at element 2: `). - **Widest diff:** the switch from `dataTypeLookup` to `dataTypes` on `ControlStack` and `ContractSourceContext` touches about a hundred test files, most by one line. - **User-visible message changes**, all listed with before-and-after rows in the app upgrade fragment: `@default(uuid(5))` now says `Expected one of: 4 | 7` at `5`; a refused `@default` value says `write a number` instead of `it casts from pg/int2`; a column type nothing writes is told to write `` sql`...` ``; a list element the column's list cast does not take names the element types it takes. - **Spans:** `PSL_VALUE_TYPE_INCOMPATIBLE` and `PSL_INVALID_LITERAL` from `@default` point at the written value or list element. The two default-only codes, `PSL_DEFAULT_LIST_EXPECTED` and `PSL_INVALID_DEFAULT_LITERAL`, still point at the attribute. - **Naming:** "body" is what is written between a tagged literal's quotes; "text" is the canonical value. `TaggedLiteralCanonicalization.text`, `TaggedLiteralExprAst.text()`, `parseJsonText` and `checkSqlDefaultText` follow that rule. - **The binder requires `dataTypes`** because it also builds spec contexts. `createSqlBinder` and `createMongoBinder` both take it. - **Language server:** `LspControlStack.dataTypes` comes from the control stack. Completion for a `dataTypeValue` argument returns nothing yet; the next slice adds it. - **Three tests `main` added for date and time defaults** expected `PSL_INVALID_DEFAULT_LITERAL`. A quoted date is read as text and the column type's cast refuses it, which #30534 reports as `PSL_INVALID_LITERAL`; the tests now expect that code. - **Three tarball tests cannot run on the author's machine** (`pnpm install` in their scratch project refuses `@vercel/[email protected]`). CI is the check for them. - **Project files.** `projects/sql-expression-literals/` holds the spec, design, plan, review reports and status. It is transient and is deleted at project close-out. ## Behavior changes & evidence - **The cast rule for one written value is framework code.** `packages/1-framework/1-core/framework-components/src/shared/written-value.ts`. Evidence: `framework-components/test/written-value.test.ts` (each written kind and refusal; a cast that changes the value; `admittedTags` order; `describeAdmittedForms` for a tag type, a boolean type, a number type reached through a classifier). - **A PSL expression reads as a written scalar or says why not.** `packages/1-framework/2-authoring/psl-parser/src/written-scalar.ts`. Evidence: `psl-parser/test/written-scalar.test.ts`, one case per expression kind. - **`dataTypeValue` admits a literal by type and refuses at the value with the general codes.** `packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/data-type-value.ts`. Evidence: `psl-parser/test/attribute-spec-combinators.data-type-value.test.ts` (every diagnostic with code, message and span; inside a `funcCall` that is an arm of `oneOf`; an unregistered type builds but does not parse), and `test/integration/test/authoring/data-type-value.test.ts` on the assembled Postgres and SQLite stacks. - **`oneOf` routes a named call to its `funcCall` alternative.** `psl-parser/src/attribute-spec/combinators/one-of.ts`. Evidence: the same combinator test file (`nanoid("8")` at `"8"`; `other(1)` still `Expected one of`; a dotted or colon-qualified callee falls through; two alternatives of one name fall through), and `contract-psl/test/interpreter.defaults.functions.test.ts` for `cuid()`, `uuid(5)` and `nanoid(1)`. - **The stack and every spec context carry `dataTypes`.** `framework-components/src/control/control-stack.ts`, `psl-parser/src/attribute-spec/spec-context.ts`, `binder.ts`, `language-server/src/lsp-control-stack.ts`. Evidence: `language-server/test/config-resolution.test.ts` (passed through by identity), the Mongo `contract-psl` interpreter tests, `psl-parser/test/binder.test.ts`. - **`@default` reads and words its values through the framework.** `contract-psl/src/data-type-default.ts`, `psl-column-resolution.ts`. Evidence: `contract-psl/test/interpreter.defaults.data-types.test.ts` (whole messages and spans, including a vector column's list cast and an unknown tag inside a list) and the Prisma 7 defaults test. - **Docs.** ADR 231 (the combinator and the `oneOf` rule), ADR 249 (the context carries `dataTypes`), ADR 254 (the scalar cast rule is framework code; `@default` reports at the written value), `docs/reference/error-reference.md`, `docs/reference/psl-editor-tooling-tagged-literals.md`, `docs/reference/codec-authoring-guide.md`. ## Compatibility / migration / risk - **Contracts:** no change. `fixtures:check` shows no `contract.json` change. - **Schema authors:** no schema changes. The message and span changes above each have a row in the app upgrade fragment. - **Extension authors:** `ContractSourceContext.dataTypes` replaces `dataTypeLookup`; `ControlDefaultRegistries` has no `dataTypeEntries` and a spec reads tags from `ctx.dataTypes.entries`; `entryForTag`, `WrittenValue` and `DataTypeSupport` moved to `@internal/framework-components/authoring`; `TaggedLiteralCanonicalization.body` is `text`; `checkSqlDefaultBody` and its neighbours are `checkSqlDefaultText`, `reservedSqlDefaultText` and `UNSAFE_DEFAULT_TEXT`; `createBinder`, `createSqlBinder` and `createMongoBinder` require `dataTypes`; `oneOf` routes a named call as described. The extension upgrade fragment has the full table. - **Code that asserts PSL diagnostic spans or `Expected one of` text:** see the app upgrade fragment. ## Testing performed On the final HEAD: - `pnpm build`, `pnpm typecheck`, `pnpm lint`, `pnpm lint:deps`, `pnpm lint:casts` (delta 0), `pnpm lint:throws` (delta 0), `pnpm check:error-reference`, `pnpm lint:framework-vocabulary` (272 of 272), `pnpm fixtures:check` (tree clean), `pnpm check:upgrade-coverage --mode pr` against the merge base - `pnpm test:packages`: 1425 files pass; the 3 tarball files fail on the registry refusal above; files that timed out under load pass alone - Targeted integration files (`test/authoring/**`, `test/number-defaults/**`, `test/date-time-defaults/**`, and the Mongo and value-object files whose imports changed). The full `test:integration` suite runs in CI. - Manual QA: the slice 2t script in `projects/sql-expression-literals/manual-qa.md` reads each changed diagnostic as a user would; the run is recorded there - Two rounds of architect and code review, reports in `projects/sql-expression-literals/slice-reviews/2t/` and `2t-round-2/`; every finding is fixed ## Follow-ups - TML-3288: `@@index`, `@@fullTextIndex`, `@@check` and policy predicates take `sql` literals through `dataTypeValue`. - TML-3289: the TypeScript builder takes `sql` values. - The project "Data types own column types" types default-function arguments with `dataTypeValue`; a default-function signature will be built from the stack's data types, as recorded in that project's notes. ## Alternatives considered - **Leave the cast rule in the SQL family and have the parser call back into it.** Rejected: the framework's combinators cannot import family code, and the rule is not SQL-specific. - **A "tagged literal" parameter kind with its own error for plain strings.** Rejected: it describes syntax, not types. The cast rule already refuses a value of another type, and one mechanism serves `sql`, `json` and any future tag. - **Leave `oneOf` alone and forbid `dataTypeValue` as a direct arm of it.** Rejected: every `@default` function is an arm of `oneOf`, so the argument's refusal would never reach the author. Routing a named call to its one `funcCall` alternative fixes that for every attribute. - **Keep the old `@default` wording, `it casts from pg/int2`.** Rejected: a list of cast source ids tells the author which types exist, not what to write; `write a number` does, and one wording serves both `@default` and typed arguments. - **Make `dataTypes` optional on the spec context.** Rejected: an absent value would silently disable the cast rule. The language server passes `EMPTY_DATA_TYPES` when it has no stack, which makes the case explicit. - **Move list casts into the framework too.** Rejected for this slice: only `@default` takes lists, and the six places the next slice types take scalars. ADR 254 records the split. ## Checklist - [x] All commits are signed off (`git commit -s`) per the [DCO](../CONTRIBUTING.md#developer-certificate-of-origin-dco). - [x] I read [CONTRIBUTING.md](../CONTRIBUTING.md) and the change is scoped to one logical concern. - [x] Tests are updated. - [x] The PR title is in `TML-NNNN: <sentence-case title>` form. - [x] The **Skill update** section above is filled in. ## Notes for the reviewer See Reviewer notes above. Agent: charon-96 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Attribute specifications can now validate values against their receiving data types, with clearer guidance when a value is incompatible. * **Bug Fixes** * Default-value diagnostics now point to the invalid value or list element and distinguish unsupported list casts from invalid element types. * Invalid arguments to uniquely matched function calls now receive focused diagnostics instead of a generic alternatives error. * **Documentation** * Updated authoring and upgrade guidance for literal validation, diagnostics, and default values. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Will Madden <[email protected]>
## At a glance The SQL expression literals project is finished. Raw SQL is one value everywhere: ```prisma @@check(expression: sql` owner_id > 0 AND char_length(email) > 0 `, name: "profile_valid") ``` ```ts check({ expression: sql`owner_id > 0 AND char_length(email) > 0`, name: 'profile_valid' }); ``` ```ts // generated migration.ts checkExpression('profile_valid_5901ae2d', sql`owner_id > 0 AND char_length(email) > 0`) ``` This PR closes the project: it deletes `projects/sql-expression-literals/`, after moving the decisions that lived only there into ADR 268, and records two lessons from the project in the team's Drive calibration. ## Decision The project's transient files go. What must outlive them now lives in ADRs, the subsystem docs, Drive calibration and Linear: - **ADR 268** gains four alternatives that were recorded only in the project's design notes: holding opaque SQL in DDL as the query AST's `RawExpr`, migration functions that take only `sql` values, leaving generated migration files on strings, and a public builder for `sql` values from computed strings. Its status line now lists `sql` values in generated migration files as built. - **`drive/calibration/failure-modes.md`** gains F47 (a stack of PRs outlives its base's squash merge, and the last PR passes 250 commits, which the DCO check cannot read) and F48 (a new committed contract fixture fails the planner golden test, which only the merge queue runs). **`drive/calibration/dod.md`** adds the planner golden step to the slice gate before queueing. - **`projects/data-types-completion/design-notes.md`** pointed at this project's design file; it now points at ADR 231, ADR 254 and TML-3367. ## Where each project decision lives | Decision (project design notes) | Durable home | | --- | --- | | Every place that holds raw SQL takes a `sql` literal | ADR 268, ADR 129 | | Plain strings are refused | ADR 268 | | A `sql` literal is a value of the data type `sql/expression`; only `@default` checks the text | ADR 268, ADR 254, ADR 129 | | The SQL family defines and registers `sql/expression` (the notes' first version said each target registers it; the family does) | ADR 268, ADR 254 | | The only tag is `sql` | ADR 268, ADR 129 | | Specs name the data type an argument receives (`dataTypeValue`) | ADR 231, ADR 249, ADR 262 | | The TypeScript builder takes `sql` values | ADR 268, ADR 129 | | `contract infer` prints `sql` literals, and skips or notes text that would not read back | ADR 129, ADR 268 | | Opaque SQL is its own DDL value, `OpaqueSql` | Migration System subsystem doc, "Opaque SQL in DDL"; ADR 268 (alternative) | | Migration files write `sql` values when they read back unchanged | ADR 195 ("Recorded exception"), ADR 268, Migration System doc | | Wire names keep line breaks in bodies with `--` | ADR 234 | | One set of codes for cast-rule refusals | ADR 268, ADR 254 | | The decision gets its own ADR | ADR 268 | | The typed argument ships first, for the "Data types own column types" project | Delivered as TML-3367; the default-function argument work is TML-3389 | | Grammar versus database values | ADR 231 | ## Project definition of done - **Delivered:** all seven slices merged. | Slice | PR | Linear | | --- | --- | --- | | 2a | prisma#30534 | TML-3296 | | 2t | prisma#30539 | TML-3367 | | 1 | prisma#30546 | TML-3287 | | 4 | prisma#30554 | TML-3290 | | 2b | prisma#30550 | TML-3288 | | 3 | prisma#30558 | TML-3289 | | 5 | prisma#30677 | TML-3297 | Every Linear issue is Done. - **Review and manual QA:** every slice that changed what a user sees had design and code reviews, a fixes check, and a manual QA run. - **Follow-ups filed:** - TML-3554: two Postgres migration operations paste raw SQL into DDL as strings. - TML-3555: a raw SQL column default cannot hold a `--` comment. A gap found in QA, `now() - interval '1 day'` failing apply's default check, is on TML-2362, which replaces that comparison. Two deferred items need no ticket: - `contract infer` and defaults that do not read back: slice 3 decided and built it. - A builder for `sql` values from computed strings: recorded in ADR 268 as not offered. - **References:** nothing outside the deleted folder points into it. ## Testing performed - `pnpm lint:docs`, `pnpm lint:legacy-name` and `pnpm check:upgrade-coverage --mode pr` pass. - This PR changes only docs, Drive calibration and the deleted project folder. ## Linked issue Closes out the Linear project [SQL expression literals](https://linear.app/prisma-company/project/sql-expression-literals-c8a6659e7f4c) (TML-3282). ## Skill update n/a — docs and project files only. ## Checklist - [x] All commits are signed off (`git commit -s`) per the [DCO](../CONTRIBUTING.md#developer-certificate-of-origin-dco). - [x] I read [CONTRIBUTING.md](../CONTRIBUTING.md) and the change is scoped to one logical concern. - [x] Tests are updated (n/a, docs only). - [x] The PR title is in `TML-NNNN: <sentence-case title>` form. - [x] The **Skill update** section above is filled in. ## Alternatives considered - **Keep the project folder as a record.** Rejected: its spec, plan, design and status describe a project that no longer exists, and the decisions worth keeping now live in ADRs. - **Move the design notes into `docs/` as they are.** Rejected: they are a log written during the project, and each decision now has an ADR or subsystem-doc home. Agent: lagertha-65 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Clarified how migration functions and generated migration files represent SQL, including how DDL is stored and the limits on creating SQL values from computed strings. * Updated slice planning guidance to require running the planner golden test in write mode and reviewing recorded DDL when committed contract manifests change. * Added guidance for handling stacked pull requests that exceed the DCO commit limit and contract-fixture changes that fail merge-queue golden tests. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Linked issue
Refs TML-3296. First slice of the Linear project SQL expression literals; decision ticket TML-3282. Follow-up slices: TML-3367, TML-3288, TML-3289.
Summary
The
sqltag in PSL used to be a special case that bypassed the data type rule every other written value follows. This PR makes it the tag of a data type,sql/expression, owned and registered by the SQL family, so that later slices can give index predicates, check constraints and policies the same type and raw SQL is written one way everywhere.Skill update
No skill change. The written form users see,
@default(sql`...`), is unchanged. The two upgrade fragments underupgrade-instructions/pending/sql-is-a-data-type/record the removed prefixed tags, the renamed diagnostic codes and the removed extension-author API; the release process folds them into theprisma-8upgrade skill.At a glance
These three defaults emit exactly the same
contract.jsonas before. What changed is what thesqltag is. Before this PR it was a special "lowering entry": a tag that named no data type and turned its own text into a default expression. Nowsqlis the tag of a data type,sql/expression, defined once inpackages/2-sql/1-core/contract/src/sql-expression.ts:Decision
This PR ships three things.
sql/expressionis a data type, and the SQL family owns it. The family descriptor registers the type and its authoring entry, so both SQL targets get the same one and a new SQL target has nothing to remember. The type declares no casts, and the family refuses any stack in which another data type declares a cast from it. ADR 254 records the rule; ADR 129 is rewritten around "the tag names the data type of the text".authoring.dataTypesis aDataTypeAuthoringEntrykeyed by a registered data type id. The prefixed tagspg.sqlandsqlite.sql, which each adapter registered as aliases, are gone.@defaultreads asqlliteral as a value ofsql/expressionand keeps its own checks on the SQL text (nonow(), no;, noSELECT). Refusals that come from the cast rule use the general codes, and one code is renamed so its name says what it means.Later slices in the project make
@@index(where:),@@check(expression:)and policy predicates take the same type, so that raw SQL is written the same way everywhere in a schema. This slice only changes whatsqlis, sofixtures:checkshows nocontract.jsonchange.Reviewer notes
packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts. The oldlowerTaggedLiteralbecamereadTaggedLiteral: it looks the tag up and canonicalizes the body, nothing else.@defaultthen reads the value through the samereadValuepath as every other written value and only afterwards branches on whether the value's type issql/expression.PSL_UNKNOWN_DEFAULT_LITERAL_TAGisPSL_UNKNOWN_LITERAL_TAG,PSL_INVALID_JSON_LITERALis folded intoPSL_INVALID_LITERAL, andPSL_DEFAULT_TYPE_INCOMPATIBLEsplits intoPSL_VALUE_TYPE_INCOMPATIBLE(cast rule) andPSL_DEFAULT_LIST_EXPECTED(a single value on a list column). The table in the app upgrade fragment lists every row.sql, jsonwhere they saidjson, sql, pg.sql.sqlliteral inside a list literal used to have its own message. It is now refused by the cast rule like any other element the column type does not take, and reported at the@defaultattribute. The upgrade fragment says to write the whole list as onesqlliteral./componentsentry of@internal/framework-components(runtimeError,isRuntimeError,RuntimeErrorEnvelope), because shared-plane code in@internal/sql-contractcannot import/runtime. The/runtimeentry keeps exporting them too.contract inferdoes not see family data types. Its default mapping builds from the target's own lists. That is existing behaviour, it changes no output, and it is out of scope here. It is recorded in the project's design so the slice that touches the printer can decide.all-shells-tarball,module-identity,cross-shell-tarball, plus the twopackagingintegration files):pnpm installin their scratch project refuses@vercel/[email protected]as a "high-risk trust downgrade". That is the registry. CI is the check for them.projects/sql-expression-literals/holds the spec, design, plan, review reports and status of the whole project. It is transient and is deleted at project close-out, once its decisions have moved into the ADRs.Behavior changes & evidence
sql/expression; the targets do not.packages/2-sql/9-family/src/core/control-descriptor.tscarriesdataTypesandauthoring.dataTypes;packages/3-targets/3-targets/postgres/src/core/data-type-entries.tsand the SQLite twin list only their own types. Evidence:test/integration/test/authoring/sql-expression-registration.test.tsassembles a real stack per target (Postgres with all five shipped extension packs) and checks the registered declaration and entry are the family's.sql/expression.assertNothingCastsFromSqlExpressioninpackages/2-sql/1-core/contract/src/sql-expression.ts, called bycreateSqlFamilyInstance, throwsCONTRACT.DATA_TYPE_CASTS_FROM_SQL_EXPRESSION, naming the type and the component that registered it. For that,ControlStackgainsdeclaredDataTypes, the listassembleDataTypesalready builds, with each type's contributor. Evidence:packages/2-sql/9-family/test/control-instance.sql-expression-casts.test.ts,packages/3-targets/3-targets/postgres/test/data-types.test.ts.packages/1-framework/1-core/framework-components/src/shared/framework-authoring.tsandcontrol-stack.ts: every entry key must be a registered data type id. Evidence:packages/1-framework/1-core/framework-components/test/data-type-assembly.test.ts.pg.sqlandsqlite.sqlare unknown tags. The adapters'data-type-authoring.tsfiles are deleted;packages/3-targets/6-adapters/postgres/src/exports/control.tsregisters the target's entries unchanged. Evidence:packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.tagged-literal.test.ts(Unknown literal tag "pg.sql". Known tags: sql, json.).@defaultreads thesql/expressionvalue and keeps its SQL checks.packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts,data-type-default.ts. Evidence:interpreter.defaults.tagged-literal.test.ts(scalar and list columns, reservednow(), unsafe text,sqlinside a list),interpreter.defaults.data-types.test.ts(every refusal kind with its code and whole message).contract inferprints raw defaults through the one tagged-literal printer, including the double-quote form for a body holding a backtick.packages/2-sql/9-family/src/core/psl-build/default-mapping.ts. Evidence:packages/2-sql/9-family/test/psl-build/default-mapping.test.ts,packages/3-targets/3-targets/postgres/test/psl-infer/inferred-psl.round-trip.test.ts.docs/reference/error-reference.mdhas the new codes and dropsPSL_INVALID_JSON_LITERAL; the contract-psl README and the editor-tooling doc tell the body (what is written between the quotes) from the text (the canonical value).Compatibility / migration / risk
contract.jsonchange for any fixture.pg.sqlandsqlite.sqlare refused; replace the tag withsqland leave the text. No migration follows, because the stored default is the same.AuthoringDataTypeEntry, the lowering helpers,TaggedLiteralValue,sqlDefaultLiteralTagEntryand the adapters'create*DataTypeEntriesare removed; the extension upgrade fragment has the replacement table. A third-party SQL target registers nothing forsql; one that registerssql/expressionitself fails assembly withCONTRACT.DATA_TYPE_DUPLICATE.Testing performed
On the final HEAD (a merge of
mainatd501bfbe69plus the round 2 review fixes):pnpm build,pnpm typecheck,pnpm lint,pnpm lint:deps,pnpm lint:casts(delta 0),pnpm lint:throws(delta 0),pnpm check:error-reference,pnpm lint:framework-vocabulary(272 of 272),pnpm fixtures:check(tree clean)pnpm check:upgrade-coverage --mode pragainst the merge basepnpm test:packages: 1418 files pass; the 3 tarball files fail on the registry refusal above; 5 files that timed out while another test run shared the machine pass alonetest/authoring/**,test/number-defaults/**, the CLI init-templates e2e and the Mongo insert-many file): 186 tests pass. The fulltest:integrationsuite runs in CI.projects/sql-expression-literals/manual-qa.mdreads each new diagnostic as a user would; the run on this tip is recorded thereprojects/sql-expression-literals/slice-reviews/; every finding is fixedFollow-ups
dataTypeValuebuilding block).@@index,@@fullTextIndex,@@checkand policy predicates takesqlliterals.sqlvalues.Alternatives considered
sql/expression. This is what the first version of the slice did. Rejected because the type is the same on every target and nothing casts from it, so the owner and the registrar should be one component; a new SQL target would otherwise have to remember to register it.pg.sqlandsqlite.sqlas aliases. Rejected: an alias is a second way to write the same value, and the stack already names the target.sqlthe one written value that bypassed the type rule, which is the exception ADR 254 promised to remove, and it blocked giving index, check and policy predicates the same type.sql/expression" in docs only. Rejected after the first review: a pack that declared such a cast would turn asqlliteral into a value of another type with no diagnostic, so the family checks it when it creates its control instance.sqlliteral inside a list literal with its own message. Rejected: it is an element the column's type does not take, and the cast rule already says so with the same code as every other such element.Checklist
git commit -s) per the DCO.TML-NNNN: <sentence-case title>form.Notes for the reviewer
See Reviewer notes above.
Agent: charon-96
Summary by CodeRabbit
New Features
sqltag. Thepg.sqlandsqlite.sqltags are no longer recognized.Bug Fixes
Documentation