Skip to content

TML-3296: sql is the tag of the SQL family's data type sql/expression - #30534

Merged
wmadden merged 56 commits into
mainfrom
tml-3296-sql-expression-data-type
Sep 30, 2026
Merged

wmadden merged 56 commits into
mainfrom
tml-3296-sql-expression-data-type

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

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 sql tag 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 under upgrade-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 the prisma-8 upgrade skill.

At a glance

model Post {
  id        String   @id @default(sql`gen_random_uuid()`)
  createdAt DateTime @default(sql`(now() + interval '1 hour')`)
  tags      String[] @default(sql`'{}'::text[]`)
}

These three defaults emit exactly the same contract.json as before. What changed is what the sql tag 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. Now sql is the tag of a data type, sql/expression, defined once in packages/2-sql/1-core/contract/src/sql-expression.ts:

export const SQL_EXPRESSION_DATA_TYPE_ID: DataTypeId = dataTypeId('sql/expression');
export const sqlExpressionDataType: DataType = dataType(SQL_EXPRESSION_DATA_TYPE_ID, {});
export const sqlExpressionAuthoringEntry: DataTypeAuthoringEntry = {
  written: { kind: 'tag', tag: 'sql', parse: (text) => text },
  print: (value) => sqlTextFromCanonical(value),
  documentation: "A SQL expression in the target database's language. Prisma passes it to the database unchanged.",
};

Decision

This PR ships three things.

  1. sql/expression is 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".
  2. The framework loses the lowering-entry kind. Every entry in authoring.dataTypes is a DataTypeAuthoringEntry keyed by a registered data type id. The prefixed tags pg.sql and sqlite.sql, which each adapter registered as aliases, are gone.
  3. @default reads a sql literal as a value of sql/expression and keeps its own checks on the SQL text (no now(), no ;, no SELECT). 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 what sql is, so fixtures:check shows no contract.json change.

Reviewer notes

  • The largest change is in packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts. The old lowerTaggedLiteral became readTaggedLiteral: it looks the tag up and canonicalizes the body, nothing else. @default then reads the value through the same readValue path as every other written value and only afterwards branches on whether the value's type is sql/expression.
  • Codes changed, messages mostly did not. PSL_UNKNOWN_DEFAULT_LITERAL_TAG is PSL_UNKNOWN_LITERAL_TAG, PSL_INVALID_JSON_LITERAL is folded into PSL_INVALID_LITERAL, and PSL_DEFAULT_TYPE_INCOMPATIBLE splits into PSL_VALUE_TYPE_INCOMPATIBLE (cast rule) and PSL_DEFAULT_LIST_EXPECTED (a single value on a list column). The table in the app upgrade fragment lists every row.
  • The known-tags order flips. The family assembles before the target, so the unknown-tag message and the completion list say sql, json where they said json, sql, pg.sql.
  • A sql literal 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 @default attribute. The upgrade fragment says to write the whole list as one sql literal.
  • The runtime error envelope is now published from the shared /components entry of @internal/framework-components (runtimeError, isRuntimeError, RuntimeErrorEnvelope), because shared-plane code in @internal/sql-contract cannot import /runtime. The /runtime entry keeps exporting them too.
  • The cast check runs when the SQL family creates its control instance, which every CLI command goes through before it emits, prints, infers, plans or verifies. The language server does not create one, so it does not report this error. ADR 254 and the error reference say so.
  • contract infer does 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.
  • Three tarball tests cannot run on the author's machine (all-shells-tarball, module-identity, cross-shell-tarball, plus the two packaging integration files): pnpm install in their scratch project refuses @vercel/[email protected] as a "high-risk trust downgrade". That is the registry. CI is the check for them.
  • Project files. 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

  • The family registers sql/expression; the targets do not. packages/2-sql/9-family/src/core/control-descriptor.ts carries dataTypes and authoring.dataTypes; packages/3-targets/3-targets/postgres/src/core/data-type-entries.ts and the SQLite twin list only their own types. Evidence: test/integration/test/authoring/sql-expression-registration.test.ts assembles a real stack per target (Postgres with all five shipped extension packs) and checks the registered declaration and entry are the family's.
  • No data type may cast from sql/expression. assertNothingCastsFromSqlExpression in packages/2-sql/1-core/contract/src/sql-expression.ts, called by createSqlFamilyInstance, throws CONTRACT.DATA_TYPE_CASTS_FROM_SQL_EXPRESSION, naming the type and the component that registered it. For that, ControlStack gains declaredDataTypes, the list assembleDataTypes already 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.
  • The lowering-entry kind is gone. packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts and control-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.sql and sqlite.sql are unknown tags. The adapters' data-type-authoring.ts files are deleted; packages/3-targets/6-adapters/postgres/src/exports/control.ts registers 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.).
  • @default reads the sql/expression value 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, reserved now(), unsafe text, sql inside a list), interpreter.defaults.data-types.test.ts (every refusal kind with its code and whole message).
  • contract infer prints 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. docs/reference/error-reference.md has the new codes and drops PSL_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

  • Contracts: no shape change and no contract.json change for any fixture.
  • Schema authors: pg.sql and sqlite.sql are refused; replace the tag with sql and leave the text. No migration follows, because the stored default is the same.
  • Extension authors: AuthoringDataTypeEntry, the lowering helpers, TaggedLiteralValue, sqlDefaultLiteralTagEntry and the adapters' create*DataTypeEntries are removed; the extension upgrade fragment has the replacement table. A third-party SQL target registers nothing for sql; one that registers sql/expression itself fails assembly with CONTRACT.DATA_TYPE_DUPLICATE.
  • Code that asserts PSL diagnostic codes: see the table in the app upgrade fragment.

Testing performed

On the final HEAD (a merge of main at d501bfbe69 plus 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 pr against the merge base
  • pnpm 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 alone
  • Targeted integration files (test/authoring/**, test/number-defaults/**, the CLI init-templates e2e and the Mongo insert-many file): 186 tests pass. The full test:integration suite runs in CI.
  • Manual QA: the script in projects/sql-expression-literals/manual-qa.md reads each new diagnostic as a user would; the run on this tip is recorded there
  • Two rounds of architect and code review, reports in projects/sql-expression-literals/slice-reviews/; every finding is fixed

Follow-ups

  • TML-3367: an argument declares the data type it receives (the dataTypeValue building block).
  • TML-3288: @@index, @@fullTextIndex, @@check and policy predicates take sql literals.
  • TML-3289: the TypeScript builder takes sql values.

Alternatives considered

  • Each target registers 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.
  • Keep pg.sql and sqlite.sql as aliases. Rejected: an alias is a second way to write the same value, and the stack already names the target.
  • Keep a separate lowering-entry kind for tags that produce a default expression. Rejected: it made sql the 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.
  • Enforce "nothing casts from sql/expression" in docs only. Rejected after the first review: a pack that declared such a cast would turn a sql literal into a value of another type with no diagnostic, so the family checks it when it creates its control instance.
  • Refuse a sql literal 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

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form.
  • The Skill update section above is filled in.

Notes for the reviewer

See Reviewer notes above.

Agent: charon-96

Summary by CodeRabbit

  • New Features

    • SQL expressions are represented as a registered data type and can be written with the unprefixed sql tag. The pg.sql and sqlite.sql tags are no longer recognized.
    • Tagged literals are printed with quoting and escaping that preserves special characters and multiline text.
  • Bug Fixes

    • Improved diagnostics for unknown tags, incompatible values, invalid literals, and single values supplied where a list is required.
    • SQL expressions are rejected where data-type casts from SQL expressions are not supported.
  • Documentation

    • Updated authoring, error-reference, and upgrade guidance for tagged literals, SQL defaults, and diagnostic changes.

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]>
…d literal printer

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]>
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]>
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]>
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]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner September 30, 2026 11:28
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: cdcdc172-a53a-4faa-8fdd-0dbd5bb36310

📥 Commits

Reviewing files that changed from the base of the PR and between 656249c and 2227335.

⛔ Files ignored due to path filters (29)
  • projects/sql-expression-literals/README.md is excluded by !projects/**
  • projects/sql-expression-literals/design-notes.md is excluded by !projects/**
  • projects/sql-expression-literals/design.md is excluded by !projects/**
  • projects/sql-expression-literals/dispatches/2a-implementer-brief.md is excluded by !projects/**
  • projects/sql-expression-literals/dispatches/2a-review-fixes-brief.md is excluded by !projects/**
  • projects/sql-expression-literals/dispatches/2a-review-fixes-findings.md is excluded by !projects/**
  • projects/sql-expression-literals/dispatches/2a-round-2-fixes-brief.md is excluded by !projects/**
  • projects/sql-expression-literals/handover.md is excluded by !projects/**
  • projects/sql-expression-literals/manual-qa.md is excluded by !projects/**
  • projects/sql-expression-literals/plan.md is excluded by !projects/**
  • projects/sql-expression-literals/research/artefacts-docs.md is excluded by !projects/**
  • projects/sql-expression-literals/research/attribute-specs.md is excluded by !projects/**
  • projects/sql-expression-literals/research/block-params.md is excluded by !projects/**
  • projects/sql-expression-literals/research/block-specs.md is excluded by !projects/**
  • projects/sql-expression-literals/research/data-types.md is excluded by !projects/**
  • projects/sql-expression-literals/research/ddl.md is excluded by !projects/**
  • projects/sql-expression-literals/research/design-review-architect.md is excluded by !projects/**
  • projects/sql-expression-literals/research/design-review-principal-engineer.md is excluded by !projects/**
  • projects/sql-expression-literals/research/design-verification.md is excluded by !projects/**
  • projects/sql-expression-literals/research/infer-lsp.md is excluded by !projects/**
  • projects/sql-expression-literals/research/rebase-delta.md is excluded by !projects/**
  • projects/sql-expression-literals/research/review-followups.md is excluded by !projects/**
  • projects/sql-expression-literals/research/ts-builder.md is excluded by !projects/**
  • projects/sql-expression-literals/slice-reviews/2a-round-2/code-review.md is excluded by !projects/**
  • projects/sql-expression-literals/slice-reviews/2a-round-2/system-design-review.md is excluded by !projects/**
  • projects/sql-expression-literals/slice-reviews/2a/code-review.md is excluded by !projects/**
  • projects/sql-expression-literals/slice-reviews/2a/system-design-review.md is excluded by !projects/**
  • projects/sql-expression-literals/spec.md is excluded by !projects/**
  • projects/sql-expression-literals/status.md is excluded by !projects/**
📒 Files selected for processing (3)
  • docs/reference/error-reference.md
  • packages/1-framework/1-core/framework-components/src/exports/authoring.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change registers sql/expression as a SQL-family data type and routes tagged literals through data-type authoring entries. It updates SQL default resolution, cast checks, diagnostics, PostgreSQL and SQLite registration, tagged-literal printing, tests, documentation, and upgrade instructions.

Changes

SQL expressions as typed values

Layer / File(s) Summary
Data-type authoring and tagged-literal printing
packages/1-framework/1-core/framework-components/src/control/control-stack.ts, packages/1-framework/1-core/framework-components/src/shared/*, packages/1-framework/1-core/framework-components/test/*, packages/1-framework/2-authoring/psl-parser/*, packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts
Authoring contributions now use data-type entries instead of lowering entries. The assembled stack exposes registered types with contributor IDs. The shared printer formats tagged literals, and parser and completion tests use the revised tag examples and registrations.
SQL expression type and cast validation
packages/2-sql/1-core/contract/*, packages/2-sql/9-family/src/core/control-descriptor.ts, packages/2-sql/9-family/src/core/control-instance.ts, packages/2-sql/9-family/test/control-instance.sql-expression-casts.test.ts, test/integration/test/authoring/sql-expression-registration.test.ts, packages/9-public/*/package.json
The SQL contract defines and exports sql/expression with the sql authoring entry. SQL family setup checks declared types for direct and list casts from this type.
Tagged-value resolution and SQL default mapping
packages/2-sql/2-authoring/contract-psl/src/*, packages/2-sql/2-authoring/contract-prisma7/src/defaults.ts, packages/2-sql/9-family/src/core/psl-build/default-mapping.ts, packages/2-sql/2-authoring/contract-psl/test/*, packages/2-sql/9-family/test/psl-build/*
Tagged text is resolved through data-type entries. SQL-expression defaults are validated before they become function defaults; other values use literal parsing and cast rules. Refusal outcomes use the updated diagnostic codes.
Target registration, diagnostics, and migration guidance
packages/3-targets/3-targets/{postgres,sqlite}/*, packages/3-targets/6-adapters/{postgres,sqlite}/*, docs/architecture docs/*, docs/reference/*, upgrade-instructions/pending/sql-is-a-data-type/*, test/integration/test/{authoring,number-defaults}/*
PostgreSQL and SQLite adapters register target data types without SQL lowering aliases. Tests and documentation describe the sql tag, diagnostic updates, and upgrade steps for removing pg.sql and sqlite.sql.

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
Loading

Suggested reviewers: sevinf

Merge Risk: ⚪ Minimal · up to 22273

The change moves the sql tag onto the SQL-family sql/expression type and removes the pg.sql and sqlite.sql aliases. No blocking issues were identified in the supplied material, and the stated test results are consistent with the change.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 22273

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected security-relevant source is schema-authored default text, and its immediate outcome is a column-default SQL expression in the authored contract. Effective database, tenant, and environment exposure depends on downstream application authority and database privileges, which were not established by this evidence.

Trust Boundaries and Controls

  • observed — The default-expression sink refuses reserved Prisma default-function spellings and screens for semicolons, SQL comment tokens, double-dollar quoting, and SELECT tokens. The same validator was used by the pre-change lowering callback. These are lexical restrictions on an intentional SQL-expression capability, not a general SQL sandbox.

Resilience and Maintainability Implications

  • observed — The new SQL-expression contract declares no casts and defines a check rejecting direct or list casts from sql/expression. This explicitly addresses the risk of treating executable SQL as an ordinary typed value. Full hydration of the check's invocation remains a coverage limitation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the primary change: making sql the tag for the SQL family’s sql/expression data type.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

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

@prisma/orm-extension-middleware-cache

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

@prisma/orm-extension-paradedb

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

@prisma/orm-extension-pgvector

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

@prisma/orm-extension-postgis

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

@prisma/orm-extension-supabase

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

@prisma/orm-family-mongo

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

@prisma/orm-family-sql

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

@prisma/orm-framework

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

@prisma/orm-mongo

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

@prisma/orm-postgres

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

@prisma/orm-sqlite

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

@prisma/orm-target-mongo

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

@prisma/orm-target-postgres

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

@prisma/orm-target-sqlite

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

@prisma/orm-toolchain

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

commit: 2227335

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 209.48 KB (+0.13% 🔺)
postgres / emit 187.88 KB (+0.19% 🔺)
mongo / no-emit 194.56 KB (+0.04% 🔺)
mongo / emit 173.94 KB (+0.01% 🔺)
cf-worker / no-emit 264.85 KB (+0.13% 🔺)
cf-worker / emit 240.63 KB (+0.15% 🔺)

…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
@wmadden
wmadden added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit d0ec426 Sep 30, 2026
27 checks passed
@wmadden
wmadden deleted the tml-3296-sql-expression-data-type branch September 30, 2026 16:36
wmadden-electric added a commit that referenced this pull request Oct 1, 2026
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]>
github-merge-queue Bot pushed a commit that referenced this pull request Oct 7, 2026
)

## 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]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-prisma__orm that referenced this pull request Oct 12, 2026
## 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]>
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.

2 participants