← Back to Pull requests

docs: add the Advanced PostgreSQL page, and fix the contract syntax rc.18 and rc.19 refuse #8574

Closed
unknown closed this pull request without merging on Oct 23, 2026 09:01 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 15:53 UTC
Author

Before, a reader who needed row-level security found the syntax under a heading on the PSL page, and an example that could not run:

policy_select user_self_read {
  target = User
  roles  = [authenticated]
  using  = "id = current_setting('app.user_id')::uuid"
}

A quoted string there has been refused since 8.0.0-rc.18 with PSL_VALUE_TYPE_INCOMPATIBLE, the page said Prisma ORM would create the authenticated role when it never does, and nothing said how the app sets app.user_id or that the role needs a GRANT.

After, one page takes the reader from the situation to a working setup:

policy_select document_owner_read {
  target = Document
  roles  = [app_user]
  using  = sql`"ownerId" = current_setting('app.user_id')::uuid`
}

with the CREATE ROLE ... LOGIN and GRANT the reader runs once, the set_config call inside a transaction, and the connection string rule.

The decision

A new page, [Advanced PostgreSQL](/orm/contract-authoring/advanced-postgresql), in Contract authoring after the TypeScript builder. It is item C7 of the docs audit, which Will decided on 2026-09-28 is documented as supported with a Limitations section; the spec is docs/orm-docs-audit/slices/08-advanced-postgresql/spec.md on the audit branch. Each section opens with the situation, then the contract for it, then what migration plan and db verify do with it, then the link to the reference entry: rows that belong to a user, an index on an expression or on some rows, a value the database must reject, a table Prisma ORM should not touch, an extension a migration needs, and adopting these from an existing database.

The Limitations section lists only what an Opus agent confirmed against prisma/orm at v8.0.0-rc.19, with the open issue for each and what to do instead. Of the eight gaps recorded on 2026-09-28, four still hold (no GRANT, no FORCE ROW LEVEL SECURITY, the @@index sort-order failure, constraints dropped from single-table variants), one was fixed in rc.13 (policy ordering), one is narrower than recorded (drift only for SQL you typed with map:), one is wider (contract infer reads only public, not only policies across schemas), and one had no source and is dropped (@@control on external tables with relations). @noCheck turns out to be removed entirely in rc.19, not only its enum form.

Stale syntax fixed on the way

  • Since rc.18 a contract's SQL is a `sql... literal. The PSL page and the TypeScript builder page showed quoted strings in twelve places (@@index, @@check, policy using and withCheck, and the builder's constraints.index, check, policySelect, policyUpdate). All twelve now use the literal, the builder examples import sql, and the prose says a quoted string is refused.

  • Since rc.19 @default(uuid()) and @default(cuid()) are refused with PSL_GENERATOR_IN_DEFAULT in a Prisma ORM 8 contract. The Auth.js, Permit.io, and Shopify guides are Prisma ORM 7 guides, so they keep @default(...); an earlier commit on this branch changed them and a later one put them back.

  • The PSL page said a role block makes Prisma ORM create the role. At rc.19 a role is referenced, never created, and db verify fails when it is missing; the page says so now.

  • Three older checker hits on the two authoring pages (two uses of "codec" in prose and one staccato run) are cleared.
  • How it was checked

    The reader-review skill's three scripts and cspell pass on every changed page; lint:links and lint:versions pass. Two cold reader rounds with the Prisma ORM 7 reader persona on the new page, a limitations check against rc.19, and a fact re-check of every claim and example against v8.0.0-rc.19.

    What a reviewer should know

  • The set_config example runs through tx.query with .returnsRow({ set_config: "pg/text@1" }), because set_config returns a row. The checker confirmed the raw query shape against the raw-queries page and the runtime.

  • migration plan writes CREATE POLICY but never CREATE ROLE or GRANT; the page shows a rawSql step with operationClass: 'widening' for the GRANT.
  • Alternatives considered

  • Put the situations on the PSL page under each construct. Rejected: the PSL page is the syntax reference, and the reader job (J8 in the audit) is "I need these together on one page".

  • List every gap from the September note. Rejected: three of them are no longer true at rc.19, so the list is the verified subset.
  • Agent: seacole-52

    🤖 Generated with Claude Code

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

    Summary by CodeRabbit

    Documentation
    Added guidance for advanced PostgreSQL features in Prisma ORM contracts, including row-level security, indexes, constraints, extensions, and existing database objects.
    Clarified migration and verification workflows, role management requirements, and current limitations.
    Updated related pages with links and clarifications about roles, index arguments, and type handling.
    * Clarified that
    migration new starts from the db ref when migrations exist, rejects unchanged contracts, and supports creating SQL- or data-only migrations with --from`.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: wmadden Review duration: 1028m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8574"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository