GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TML-3431: A Postgres full-text index can span several weighted fields, and the contract stores it as data by wmadden-electric · Pull Request #30562 · prisma/orm

Conversation

@wmadden-electric

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

At a glance

A schema author indexes a post's title and body for search, with the title counting more:

model Post {
  id       Int     @id
  title    String
  subtitle String?
  body     String?

  @@fullTextIndex([[title, subtitle], body], name: "post_search")
}

Each top-level item of the list is a weight group, strongest first. Here title and subtitle share weight A, and body gets weight B. A query names the index, and fullTextMatches and fullTextRank read its weight groups and language from the contract:

const q = websearchToTsquery(query);
const post = db.sql.public.post;
post
  .select('id')
  .where((f, fns) => fns.fullTextMatches(post.indexes.post_search, q))
  .orderBy((f, fns) => fns.fullTextRank(post.indexes.post_search, q), { direction: 'desc' })
  .build();

The index and the query search the same search document, one tsvector built from the fields, so Postgres uses the index:

(setweight(to_tsvector('english', coalesce("title", '')), 'A')
  || setweight(to_tsvector('english', coalesce("subtitle", '')), 'A')
  || setweight(to_tsvector('english', coalesce("body", '')), 'B'))

Before this change, @@fullTextIndex took one field, and a search over several fields had to be written by hand in every query.

The problem

Postgres uses an expression index only when the query contains the same expression. Searching several fields means one search document built from all of them, with a weight per group. If a query lists the fields in another order, or uses another language or weight, Postgres scans the whole table and reports no error. And the contract stored a full-text index as an opaque SQL string, so nothing could build the query from it.

The decision

A full-text index is data in the contract: an index of type fullText, which the Postgres target registers in its index type registry.

{
  "columns": ["title", "subtitle", "body"],
  "name": "post_search_2f1bb221",
  "options": { "language": "english", "weightGroups": [["title", "subtitle"], ["body"]] },
  "prefix": "post_search",
  "type": "fullText",
  "unique": false
}
  • options is the index's definition: weightGroups, the weight groups as storage column names, and language. The options schema rejects any other key. No SQL string is stored.
  • columns lists the covered columns in order. It must equal weightGroups read flat.
  • The registry entry for fullText declares accessMethod: 'gin'. In the database the index is a gin index over the search document. It never stands in for a foreign key's backing index: a relation on a covered column still gets its own backing index, because the contract build's duplicate-index pass (ADR 161) treats a fullText index as different from a plain one. A relation cannot name one with index: "<name>" either: the build refuses it, because its columns are not the index's key.

The rules of a full-text index are stated once, in fullTextIndexProblems: one to four weight groups, none empty, each column once, text columns only, and not unique. fullTextIndexProblems is called by the options schema, @@fullTextIndex, the TypeScript fullTextIndex helper, the query operations, and assertFullTextIndexes, the target's check of a contract. The target runs that check when a contract is built and when contract.json is loaded. At load it also checks the text rule against the target's codecs, and refuses a codec the target does not know.

One renderer produces the search document from { weightGroups, language }. It serves the index DDL, the schema node (the target's model of the database, which the migration planner and db verify compare), and fullTextMatches and fullTextRank. With more than one group, each field gets its group's weight, A for the first; a single group gets no weight. With more than one column, every column is wrapped in coalesce, so making a column optional or required does not change the index. One column alone renders to_tsvector('english', "title"), the expression the column operations already use. renderFullTextIndexDocument, which the target exports for extension packs, refuses weight groups that break the rules, such as an empty group.

Both authoring surfaces take weight groups. @@fullTextIndex in PSL and the fullTextIndex helper in TypeScript (from @prisma/orm-postgres/contract-builder) take one field, or a list whose items are fields or lists of fields. Both take an optional language, an optional where:, and name: or map:. Both resolve fields to storage columns, so @map is honoured. With map:, both warn with PN_EXACT_NAME_BODY_COMPARISON, because db verify compares the rendered document with the text Postgres prints back, character for character.

A query names the index it searches. The SQL builder's table proxy has indexes, beside columns: one reference per index, keyed by the name the author wrote (the name: prefix or the map: name), carrying the index's columns bound to the table's alias, its type and its options, all typed from the contract. fns.fullTextMatches and fns.fullTextRank accept a fullText index reference and take the weight groups and language from it, so the query renders exactly the expression the index covers and cannot drift from it. Giving a language with an index, or naming an index of another type, is a compile error and a runtime RUNTIME.ARGUMENT_INVALID. A key two indexes share is absent from the type. A column from a table that is not one of the query's sources is refused with ORM.ARGUMENT_INVALID when the query is built, not left to Postgres.

A document written by hand looks different. To search without an index, fullTextDocument([[f.title, f.subtitle], [f.body]]) from @prisma/orm-postgres/target/full-text builds a document, checked by the same rules as an index; such a query uses an index only if one covers the same document. A single column, fns.fullTextMatches(f.text, q), works as before. fullTextHeadline is unchanged.

The index type registry gets two optional fields, in packages/2-sql/1-core/contract/src/index-types.ts. Existing registrations set neither and are unchanged.

  • accessMethod is the access method an index of the type is created with. It defaults to the type literal. accessMethodOf(entry) reads it, and rendersIndexBody(entry) is true when it differs from the literal. Only the target can turn a type like that into an index of its access method, so when the registry is assembled, an extension pack's entry whose accessMethod differs from its type literal is refused with CONTRACT.PACK_CONTRIBUTION_INVALID.
  • columnTraits lists the codec traits every covered column must have. fullText declares ['textual']. The contract build checks it against the contract's codec lookup. It refuses an index over a column that lacks a trait with the new code CONTRACT.INDEX_INVALID. A column whose codec the lookup does not know is refused earlier in the build, with CONTRACT.CODEC_DESCRIPTOR_MISSING. This is how the text rule is checked for an index written through the general index API.

This is the storage part of ADR 260 (proposed in #30428), which builds typed search scopes on top of it.

Upgrading

A full-text index declared before this change is stored in a new form, so its storage hash and its generated name change. The schema source does not change. For @@fullTextIndex([title], name: "post_title_search") the name changes from post_title_search_724b05e5 to post_title_search_e0dd1131. The first migration after upgrading changes the index:

  • prisma migration plan from the previous contract renames it. A rename is instant. Use this for any large index.
  • prisma db update cannot tell that the old index is the new one under another name, so it drops the index and builds it again. Renaming the index by hand first avoids the rebuild.
  • db verify reports the new name as missing until the rename runs.

An index declared with map: keeps its exact name, so only the storage hash changes.

PSL_FULL_TEXT_INDEX_ONE_FIELD is gone. The new PSL diagnostics are PSL_FULL_TEXT_INDEX_TOO_MANY_GROUPS, PSL_FULL_TEXT_INDEX_EMPTY_GROUP and PSL_FULL_TEXT_INDEX_DUPLICATE_FIELD.

For extension authors: renderFullTextIndexExpression(language, column) in @internal/target-postgres/sql-utils is now renderFullTextIndexDocument({ weightGroups, language }). isFullTextIndexableCodec is removed; use fullTextIndexProblems or postgresCodecTraitsOf from the new entry @internal/target-postgres/full-text-index-authoring. An index option whose value is an array or an object now enters the name hash as JSON with sorted keys, so a wire-named index with such an option gets a new name.

Upgrade instructions for applications and for extensions are under upgrade-instructions/pending/full-text-index-weight-groups/. examples/prisma-8-demo regenerates its migration 20260922T1218_add_post_title_search, which now creates the index under its new name.

What reviewers should look at

New files in packages/3-targets/3-targets/postgres/src/:

  • core/full-text-index-definition.ts: the type literal, the options schema, the registry entry, fullTextIndexProblems, the reader fullTextIndexDefinitionOf, and assertFullTextIndexes.
  • core/full-text-search-document.ts: the renderer. Every producer of the search document calls renderFullTextDocument.
  • core/full-text-weight-groups.ts: the weights A to D, and how an author's list becomes weight groups.
  • core/postgres-codec-traits.ts: postgresCodecTraitsOf, the traits of the target's codecs, for the text rule.
  • exports/full-text-index-authoring.ts: a new export entry for authoring code. The fullTextIndex helper in packages/3-extensions/postgres imports from it. The public packages @prisma/orm-postgres and @prisma/orm-target-postgres expose it as ./target/full-text-index-authoring.

Tests:

  • test/integration/test/sql-builder/weighted-full-text-index-usage.test.ts (new): the DDL, the schema node and the query carry the same document text. Postgres prints the index and an index built from the query's document identically. EXPLAIN with sequential scans off uses the index, and does not when the grouping, the order or the language differ. A title match ranks above a body match.
  • test/integration/test/family.schema-verify.full-text-index.integration.test.ts (new): a weighted index verifies clean against what Postgres returns. A map: index is reported as changed.
  • packages/3-targets/3-targets/postgres/test/migrations/full-text-index-planning.test.ts: a change of grouping, field order or language drops and recreates the index. A change of name prefix alone renames it. An index from before this change is renamed. A nullability change plans only the column change.
  • packages/3-targets/3-targets/postgres/test/full-text-index-contract-load.test.ts (new): loading refuses mismatched columns, a unique index, invalid options and a column that is not text.

Changes outside the Postgres target

  • packages/2-sql/1-core/contract: accessMethod and columnTraits on IndexTypeEntry, and the refusal of an extension pack's type whose access method is not its literal, as above. indexTypeRegistryOf(target, extensions) takes the target and the extension packs separately, so it can tell them apart; the contract build and the SQL family instance pass the target on its own. validateIndexTypes takes an optional codec traits lookup. lowerAuthoredIndex takes the registry and warns for map: on a type whose body is rendered, so both authoring surfaces warn from one place.
  • packages/2-sql/2-authoring/contract-ts: an index's options may be a function of the resolved storage columns (IndexOptionsInput, DeferredIndexOptions). Options that name columns can only be written at lowering, because a .column() override or a naming convention decides the column names. The fullTextIndex helper uses it.
  • packages/2-sql/1-core/schema-ir: normalizeIndexOptionValue writes an array or object option value as JSON, with object keys sorted at every depth. Before, [["a","b"]] and [["a"],["b"]] hashed to the same name. No existing index option is an array or an object, so no other index is renamed.

Not in this pull request

  • Typed search scopes over these indexes: ADR 260.
  • The ORM has no weighted form: its where callback has no fns, and an operation's first argument is always the field. Weighted search from the ORM is slice 4's query fragments, which can reuse the index reference.
  • contract infer keeps a weighted index from a live database as an expression index, @@index(expression: ..., type: "gin"). It does not recover @@fullTextIndex.
  • The text check at load knows only the target's own codecs. A column stored through an extension pack's textual codec would be refused when the contract is loaded. No extension pack registers a textual codec today.

Alternatives considered

  • A gin index whose options hold the fields and language. Every reader would have to recognise a full-text index by gin plus an option, and options would hold something that is not a storage parameter. A registered type states the concept.
  • Keep an expression string and parse it back. Parsing SQL to recover fields and weights is fragile, and the contract would still store a string, not the definition.
  • Name the options key fields. Everywhere else fields means model fields, but these are storage column names. A reader would map them through the model and get the wrong column for a field with @map. weightGroups says what the value holds.
  • Wrap only nullable columns in coalesce. That makes nullability part of the expression without being part of the index's name, so a nullability change silently stops the index being used.
  • A separate resolveOptions key beside options. An index could then carry both, and lowering would silently ignore one. A function in place of the value follows the existing deferred form expression: { fields, render }.
  • Declare "cannot be unique" as a flag on the registry entry. Only fullText needs it, and its other rules are about its options. One function beside the entry states all of them.
  • Let an extension pack register a type whose access method is not its literal. The DDL names the type after USING, and only the target converts such a type into an index of its access method, so Postgres would fail the migration with an unknown access method.

Housekeeping

  • Linked issues: TML-3431. Also resolves TML-3429: the TypeScript fullTextIndex helper warns on map:. Builds on TML-3430: A foreign key names its backing index, and the contract build removes duplicate indexes #30561 (TML-3430), now merged: index types declare nothing about foreign keys.
  • Docs: ADR 210 describes access methods and the types a target converts. ADR 236, the Postgres README, the contract-ts README and the error reference describe weight groups and the new refusals.
  • Skill update: skills/prisma-8/references/contract.md and queries-postgres.md describe weight groups, the fullText type, the map: warning and the fns forms.
  • Testing performed: pnpm typecheck across the repository (171 of 171 tasks); the tests of every touched package; pnpm fixtures:check; the demo's emit:check; the integration files family.schema-verify.full-text-index, psl-print/authored-contract-roundtrip, psl-print/every-postgres-contract-roundtrip, sql-builder/full-text-index-usage, sql-builder/weighted-full-text-index-usage, sql-builder/extension-functions and sql-orm-client/extension-operations; lint:deps, lint:throws, lint:casts, lint:agent, lint:skills, lint:framework-vocabulary and check:upgrade-coverage. In examples/prisma-8-demo: migration-replay, which applies every migration, including the one that creates the full-text index, to a fresh database and verifies it against the contract; migration-integrity; and the full-text search tests.
  • 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.

Agent: shonagon-99, voldemort-62

Summary by CodeRabbit

  • New Features
    • PostgreSQL full-text indexes can now cover multiple fields in up to four weighted groups, with support for language and partial-index options.
    • Full-text search and ranking can use grouped columns. Matching the index’s field groups, order, and language enables PostgreSQL to use the index.
    • Index options can be derived from the index’s resolved storage columns.
  • Bug Fixes
    • Invalid full-text index definitions, unsupported field types, and malformed search groups are now rejected with clearer validation errors.
    • Structured index options are normalized consistently, helping keep index names and schema comparisons stable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
wmadden-electric added 22 commits October 1, 2026 09:25
@wmadden-electric
Index option values that are arrays or objects hash as JSON, so nesti…
6231d3c
…ng is kept

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
@@fullTextIndex takes weight groups and lowers to a gin index whose o…
9af7441
…ptions hold them

One renderer draws the search document from the weight groups and the
language. The gin index type validates the full-text options.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
A full-text index becomes an expression index over its search documen…
8f8e004
…t in the schema node, and prints as @@fullTextIndex

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
fullTextIndex takes weight groups; a field-tuple index can render its…
1ab5175
… options from the resolved columns

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
fullTextMatches and fullTextRank take weight groups of columns, searc…
0e11a76
…hing the document the index renders

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Re-emit the demo's full-text index in the new representation and carr…
0046b4e
…y its migration history through

The add_post_title_search migration keeps its DDL. Its end contract is
re-emitted from the migration's contract.prisma, the index takes its new
wire name, and the orphaned end snapshot is removed. migration plan --from
the previous migration produces the same operations.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Integration tests: Postgres uses the weighted full-text index, ranks …
50d5260
…title above body, and verifies it clean

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Document weight groups for @@fullTextIndex, fullTextIndex and the fns…
edd7add
… forms of fullTextMatches and fullTextRank

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Planning from the contract that stored a full-text index as an expres…
a15a84b
…sion renames the index

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Upgrade instructions: a full-text index is stored as data
e5899a2
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Error reference: the full-text index and weight-group refusals
8dd27d9
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
An index backs a foreign key only without a predicate and when its ty…
48448a3
…pe is the default or registered as backsForeignKey

Each index type registration declares backsForeignKey. Postgres declares it
for btree and hash, not for gin, gist, spgist or brin; ParadeDB's bm25 does
not. Foreign-key materialization and contract infer read the same rule, so a
full-text, gin or partial index on a foreign key column no longer stands in
for its backing index.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
@@fullTextIndex with map: warns that db verify compares the expressio…
4bbe881
…n text exactly

The PSL interpreter hands model-attribute lowering the build's warnings sink,
as it already hands it the diagnostics sink.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
ADRs 210 and 236 and the upgrade fragments describe weight groups and…
f96e979
… the foreign-key backing rule

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
An index backs a foreign key only without a predicate and when its ty…
1113921
…pe is the default or registered as backsForeignKey

Each index type registration declares backsForeignKey. Postgres declares it
for btree and hash, not for gin, gist, spgist or brin; ParadeDB's bm25 does
not. Foreign-key materialization and contract infer read the same rule, so a
full-text, gin or partial index on a foreign key column no longer stands in
for its backing index.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
contract infer reads the stack's index type registry, and an index ty…
8c8efc3
…pe without backsForeignKey is refused with a why and a fix

The target and the extension packs register index types through
indexTypeRegistryOf, which contract emit and the SQL family instance both
call. The PSL build context carries the registry's answer to infer.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
ADR 210 and upgrade instructions: an index type declares whether it b…
89ed160
…acks a foreign key

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge the foreign-key backing rule into the full-text index branch
0d96bef
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
A full-text index is an index type of its own, fullText; its document…
85effde
… coalesces every column, and its columns must be its fields

The Postgres registry gains fullText, whose options are exactly the weight
groups and the language; gin goes back to accepting any options. The schema
node renders a fullText index as a gin index over its search document.

A document of several columns wraps every column in coalesce, so it depends on
the weight groups and the language only, never on a column's nullability.

A fullText index whose columns are not the fields of its groups, in order, is
refused when a Postgres namespace is built, at authoring and at load.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
@@fullTextIndex with map: and where: warns once, not twice
8d3d654
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Re-emit fixtures and the demo for the fullText index type; integratio…
68ffdc0
…n tests read Postgres's own definition back

The demo's add_post_title_search migration keeps its DDL and takes the new
index name; migration plan --from the previous migration produces the same
operations. The weighted usage test compares the stored index definition with
one built from the query's own document, asserts the whole lowered statement,
and searches the nullable side of an outer join with the same document. The
verify test asserts the missing index by path.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Docs, ADRs 210 and 236, and upgrade instructions describe the fullTex…
b31c6b6
…t index type, coalesced documents and the db update rebuild

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

coderabbitai Bot commented Oct 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 3644ba7a-d64a-4401-b6c7-e1634d373a0f
📥 Commits

Reviewing files that changed from the base of the PR and between dc01033 and 8325cbf.

📒 Files selected for processing (18)
  • docs/architecture docs/adrs/ADR 210 - Index-type registry.md
  • docs/reference/error-reference.md
  • packages/2-sql/1-core/contract/src/index-types.ts
  • packages/2-sql/1-core/contract/test/index-types.test.ts
  • packages/2-sql/2-authoring/contract-ts/src/build-contract.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-dsl.ts
  • packages/2-sql/2-authoring/contract-ts/test/contract-builder.deferred-index-options.test.ts
  • packages/2-sql/2-authoring/contract-ts/test/contract-builder.index-type-access-method.test.ts
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/3-targets/3-targets/postgres/src/core/authoring.ts
  • packages/3-targets/3-targets/postgres/src/core/full-text-search-document.ts
  • packages/3-targets/3-targets/postgres/test/full-text-search-document.test.ts
  • packages/3-targets/3-targets/postgres/test/index-types.test.ts
  • packages/3-targets/3-targets/postgres/test/psl-infer/fixtures.ts
  • packages/3-targets/3-targets/postgres/test/psl-infer/infer-foreign-key-backing.test.ts
  • packages/3-targets/3-targets/postgres/test/psl-print/build-context.ts
  • upgrade-instructions/pending/full-text-index-weight-groups/extension/instructions.md
  • upgrade-instructions/pending/index-types-declare-foreign-key-backing/extension/instructions.md

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


📝 Walkthrough

Walkthrough

The PR adds weighted, multi-column PostgreSQL full-text indexes. Contracts store their fields, weight groups, and language; PostgreSQL validates and renders index definitions. Full-text query operations accept matching grouped documents.

Changes

PostgreSQL Full-Text Indexes

Layer / File(s) Summary
Index registry and contract lowering
packages/2-sql/1-core/contract/src/*, packages/2-sql/1-core/schema-ir/src/naming.ts, packages/2-sql/2-authoring/contract-ts/src/*, packages/2-sql/9-family/src/core/control-instance.ts, packages/0-shared/publish-surface/src/shells.ts
Index types can declare access methods and required column traits. Contract building checks traits when codec lookup is available. TypeScript index options can be callbacks over resolved storage columns. Structured index options use recursively sorted JSON for normalization and hashing.
Full-text definitions and authoring
packages/3-targets/3-targets/postgres/src/core/authoring.ts, packages/3-targets/3-targets/postgres/src/core/full-text-*, packages/3-extensions/postgres/src/contract/full-text-index.ts, packages/3-targets/3-targets/postgres/src/exports/*full-text*, packages/3-targets/3-targets/postgres/test/*full-text*
Full-text authoring accepts fields arranged in up to four weight groups. It resolves fields to storage columns and stores the groups and language in a fullText index. Validation covers empty or excessive groups, duplicate fields, unique indexes, and non-text codecs.
PostgreSQL validation and index rendering
packages/3-targets/3-targets/postgres/src/core/full-text-search-document.ts, packages/3-targets/3-targets/postgres/src/core/migrations/*, packages/3-targets/3-targets/postgres/src/core/postgres-*, packages/3-targets/3-targets/postgres/src/core/psl-*, packages/3-targets/3-targets/postgres/test/migrations/*
PostgreSQL validates stored full-text definitions and converts valid indexes to GIN schema nodes with rendered search documents. Schema construction and contract hydration validate definitions. PSL printing emits full-text attributes from stored definitions.
Weighted full-text queries
packages/3-targets/3-targets/postgres/src/core/query-operations.ts, packages/3-targets/3-targets/postgres/src/types/operation-types.ts, packages/3-targets/3-targets/postgres/test/query-operations.test.ts, packages/3-targets/6-adapters/postgres/test/*, test/integration/test/sql-builder/*
fullTextMatches and fullTextRank accept weighted groups of textual columns. They render null-safe vectors with group weights. Tests cover query lowering, match and rank results, and conditions where PostgreSQL uses or does not use the index.
Contract updates and usage documentation
docs/architecture docs/adrs/*, docs/reference/error-reference.md, examples/prisma-8-demo/*, skills/prisma-8/references/*, upgrade-instructions/pending/*, test/integration/test/family.schema-verify.full-text-index.integration.test.ts
Documentation and upgrade instructions describe the new contract shape, validation, and query behavior. The Prisma demo contract and migration snapshots use the fullText representation and updated hashes and index names.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ContractBuilder
  participant PostgresSchemaConversion
  participant FullTextDocumentRenderer
  participant QueryOperations
  participant PostgreSQL
  ContractBuilder->>PostgresSchemaConversion: fullText definition with weight groups and language
  PostgresSchemaConversion->>FullTextDocumentRenderer: definition for index document rendering
  FullTextDocumentRenderer->>PostgresSchemaConversion: rendered search document
  QueryOperations->>FullTextDocumentRenderer: grouped query document and language
  FullTextDocumentRenderer->>QueryOperations: rendered search document
  QueryOperations->>PostgreSQL: full-text match or rank query
Loading

Merge Risk: ⚪ Minimal · up to 8325c

This change adds weighted multi-column full-text indexes, with validation, rendering, and updated demo contracts and upgrade notes. I found no concrete merge-blocking problem in the supplied context. Existing indexes get new generated names, and the upgrade instructions already cover that.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 8325c

The change affects index definitions and upgrades. Checked SQL input controls remain intact, and no new privilege or data-access expansion was demonstrated. Upgrade compatibility and recovery behavior retain some uncertainty.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The reviewed flows affect search evaluation over caller-selected expressions and index DDL for the corresponding PostgreSQL namespace and table. Search input remains separate from index-definition authority. Cross-tenant and cross-environment exposure cannot be quantified without deployment and connection-authority context.

Trust Boundaries and Controls

  • observed — Raw search values still pass through typed parameter conversion, language options are checked before becoming literals, and index storage identifiers are quoted. The base-to-head query comparison preserves these controls while adding grouped documents.
  • observed — Registry construction now rejects extension entries whose effective access method differs from their type literal, reserving option-to-index-body conversion for the target. This is a stricter contribution boundary than the previous combined registration list, not evidence of a remote authentication boundary.

Resilience and Maintainability Implications

  • observed — The unchanged normal migration execute path encloses operations and marker updates in a transaction and rolls back unsuccessful execution. It uses advisory transaction locks, default prechecks, postchecks and idempotency probes, and compare-and-swap marker updates. Origin validation applies when a plan supplies an origin; live-database update deliberately omits that assertion. Live interruption and reverse-migration behavior were not exercised.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 83 functions across 65 files. (4 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: PostgreSQL full-text indexes support multiple weighted fields and store structured contract data.
Full details: Docstring Coverage

Explanation

Docstring coverage is 38.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 83 functions across 65 files. (4 skipped: 4 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
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pkg-pr-new

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

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

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

@prisma/orm-extension-middleware-cache

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

@prisma/orm-extension-paradedb

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

@prisma/orm-extension-pgvector

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

@prisma/orm-extension-postgis

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

@prisma/orm-extension-supabase

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

@prisma/orm-family-mongo

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

@prisma/orm-family-sql

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

@prisma/orm-framework

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

@prisma/orm-mongo

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

@prisma/orm-postgres

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

@prisma/orm-sqlite

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

@prisma/orm-target-mongo

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

@prisma/orm-target-postgres

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

@prisma/orm-target-sqlite

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

@prisma/orm-toolchain

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

commit: d9f8a36

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 234.08 KB (+1.78% 🔺)
postgres / emit 208.39 KB (+1.64% 🔺)
mongo / no-emit 199.1 KB (0%)
mongo / emit 177.17 KB (0%)
cf-worker / no-emit 292.57 KB (+1.52% 🔺)
cf-worker / emit 264.01 KB (+1.45% 🔺)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

wmadden-electric added 5 commits October 1, 2026 12:05
@wmadden-electric
The full-text definition reader no longer imports the codec list
08c4e6c
PostgresSchema reads full-text index definitions, and the module it reads them
from imported the codecs for isFullTextIndexableCodec, which pulled the
temporal codecs into every package that compiles PostgresSchema from source,
such as the ORM client's tests. The textual-codec check moves to its own
module.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Error reference lists the backsForeignKey refusal; test which Postgre…
1988f53
…s types back a foreign key; put the PSL build context comment back above its code

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge the foreign-key backing branch's review fixes into the full-tex…
568ac69
…t index branch

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
A fullText index cannot be unique or cover a column that is not text;…
d34e555
… one constant for the weights

fullTextIndexDefinitionOf refuses a unique fullText index, so a contract that
holds one is refused when it is built and when it loads; the printer's own
refusal for it is gone. An index type registration may name columnTraits, which
the contract build checks through the contract's codec lookup; Postgres's
fullText type requires textual. The check runs in the SQL family's index type
validation at contract build, so the module PostgresSchema imports still does
not import the codec list.

FULL_TEXT_WEIGHTS lives in index-types.ts, and the options schema and the
renderer both read their limit from it.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
ADR 210: when columnTraits is checked, and what it skips
ab04977
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric added 13 commits October 6, 2026 09:14
@wmadden-electric
Remove PSL_FULL_TEXT_INDEX_NO_FIELDS, which could never be raised
6d3d801
The @@fullTextIndex spec refuses an empty field list with PSL_INVALID_ATTRIBUTE_SYNTAX before the full-text rules run, so the PSL problem type now excludes no-fields as it excludes unique.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
constraints.index casts its options to IndexOptionsInput, which inclu…
0408b9e
…des the function form

The cast type and its reason still described options as the pack-declared object only.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Test an options function on an index with a deferred expression
3c250c7
The function receives the resolved columns of the expression fields, after a .column() override.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
The PSL interpreter no longer passes a warnings sink to model attribu…
ecd2bd0
…te lowering

This branch added it for the full-text map: warning, which now comes from the shared index lowering, and no model attribute reads it.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
The error reference gives the fullTextIndex payload the helper sends
8325cbf
Every refusal of the helper carries helper and fields. The reference also names the renderFullTextIndexDocument refusal.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
ADR 210: indexTypeRegistryOf builds the registry and refuses an exten…
5559b82
…sion type that is not an access method

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge main into the foreign-key backing branch
4176bc2
control-instance.ts keeps this branch's index-type registry import; main dropped the sql-expression import. The PSL print build context takes main's data type lookup with extra data types and keeps this branch's index type registry.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge the foreign-key backing branch, which now includes main, into t…
e063719
…he weighted full-text index branch

Generated contracts, the demo's add_post_title_search migration and its snapshots are regenerated with pnpm fixtures:emit. The migration keeps its DDL and the index name migration plan --from 20260917T0818_add_post_expires_at produces; the base's orphaned end snapshot is removed. The full-text test helpers pass the data type lookup PostgresControlAdapter now takes.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Re-record the planner manifest for the contracts the weighted full-te…
e329ec1
…xt index changes

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Full-text index tests build contracts and schema nodes with the codec…
95f8564
… and data type lookups main now requires

Columns name their data type instead of a native type, the schema-node conversion and the planner take the type lookups, and the SQL renderer takes the data type lookup and capabilities. A column whose codec no pack registers is now refused by the build itself, so the column-trait test asserts that refusal for the unknown codec and keeps that column out of the other cases.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
The weighted full-text planning test expects the planner's expression…
bdbbbd3
… as opaque SQL, as main's neighbouring cases do

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
The full-text DDL helper names the fixture's columns with the codecs …
9d1e120
…and data types of the packs it is built from

The sql-builder fixture has a pgvector column, and converting a contract to schema nodes now resolves every column's data type through the lookups.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
ADR 210: a column with an unknown codec is refused by the build befor…
a18e769
…e the index type check

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric wmadden-electric mentioned this pull request Oct 8, 2026
TML-3430: A foreign key names its backing index, and the contract build removes duplicate indexes #30561
Merged
4 tasks done
Base automatically changed from index-types-declare-foreign-key-backing to main October 8, 2026 10:54
wmadden-electric and others added 6 commits October 8, 2026 14:34
@wmadden-electric @claude
Merge main into the weighted full-text index branch
206a36e
Main carries the final foreign-key backing design from #30561. Where this
branch still had the earlier backsForeignKey design, main's version is
kept. The full-text index type keeps its accessMethod and columnTraits,
and the contract build builds the index type registry once with
indexTypeRegistryOf and passes it to index lowering and validation.

Generated contracts, the demo migration and the planner golden manifest
are taken from main here and regenerated in a following commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
Regenerate full-text fixtures and adapt tests after merging main
3289d84
The demo contract, the self-relations fixture and the demo migration that
adds the post title search are emitted again: their full-text indexes are
stored as the fullText type, so the index names change while the DDL body
stays the same. The demo migration is rewritten in place to the new index
name, and the planner golden manifest records the new names and the
weighted full-text fixture table.

Planner calls in the full-text planning tests pass the origin and
statements main now requires, and the full-text DDL helper reads the data
type lookup from the stack's dataTypes.

New tests: a relation whose column a full-text index covers still gets
its own backing index, which the foreign key names, and the planner
equality the duplicate-index pass uses tells full-text indexes apart by
weight groups, language and access method.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
ADR 210: how full-text indexes meet the duplicate-index pass
9246a31
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
Merge remote-tracking branch 'origin/main' into weighted-full-text-index
c943118
@wmadden-electric @claude
A relation cannot name a full-text index as its foreign key's index
ad86e40
A full-text index stores the columns its weight groups cover, but in the
database it is a gin index over a search document rendered from those
groups, so it cannot serve the equality lookups a foreign key needs. The
contract build now refuses a relation's index: "<name>" that names an
index of a type whose access method differs from its type literal, with
CONTRACT.ARGUMENT_INVALID reported at the relation in PSL. An index of an
access method, such as gin or hash, stays the relation's own claim. The
Postgres target's check of a loaded contract refuses a foreign key whose
stored index names a fullText index.

The column-trait check of index types takes its codec lookup as a
required argument and drops the message for an unknown codec, which the
build refuses earlier.

A full-text index and a hand-written gin index that render the same SQL
are both kept and both planned; a test now pins that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
ADR 210: a relation cannot name a converted index type, and structure…
ebe24ca
…d options compare as JSON

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden
wmadden approved these changes Oct 8, 2026
View reviewed changes
wmadden-electric and others added 3 commits October 8, 2026 17:12
@wmadden-electric @claude
Full-text operations search an index read from the table
8fb41fb
The SQL builder's table proxy gains `indexes`, beside `columns`: each of
the table's indexes under the name the contract source gave it (the
`name:` prefix or the `map:` name), as an IndexReference holding its
columns bound to the proxy's alias, its type and its options, typed from
the contract. A name more than one index shares is refused with
ORM.ARGUMENT_INVALID when it is read.

fullTextMatches and fullTextRank take as their document a full-text index
from `indexes`, one column, or a document from the new `fullTextDocument`
helper in the target's full-text entry. Given an index, they search its
weight groups in its language, so the query matches the index; a language
option with an index, an index of another type, and weight groups passed
as a bare nested array are type errors and RUNTIME.ARGUMENT_INVALID at
runtime. The bare nested-array form, new in this branch, is removed.

The weighted full-text integration test, the demo's SQL builder search and
the docs use the index form; the integration test also searches an
aliased self-join and keeps one fullTextDocument case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
ADR 210 and 236: a full-text query names the index it searches
f70d73b
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric @claude
The SQL builder refuses a column of an alias the query does not read
d9f8a36
An index read from a table proxy carries columns bound to that proxy's
alias, so it can name an alias the query never selects from or joins,
and Postgres would then fail with a missing FROM-clause entry. Building a
plan now walks the statement: each select may read the aliases of its own
sources and of the queries around it, so correlated subqueries still work,
and an update or delete may read its table. Any other column throws
ORM.ARGUMENT_INVALID naming the alias and the sources.

A name that more than one index of a table shares is left out of the
`indexes` type, matching the runtime refusal, and each table proxy builds
its index references once. The README says unnamed and derived indexes
appear under their default prefixes, and the playground type test reads
an aliased table's index only in a query on that alias.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden enabled auto-merge October 8, 2026 15:48
@wmadden
wmadden added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit 1923c35 Oct 8, 2026
24 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@wmadden
wmadden deleted the weighted-full-text-index branch October 8, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@wmadden wmadden wmadden approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@wmadden-electric @wmadden
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.