Skip to content

Use sort(field, direction) for MongoDB PSL indexes - #30636

Merged
SevInf merged 4 commits into
mainfrom
sort-fn-index
Oct 8, 2026
Merged

SevInf merged 4 commits into
mainfrom
sort-fn-index

Conversation

@StevenMcClankerton

@StevenMcClankerton StevenMcClankerton commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces MongoDB PSL field(sort: Asc | Desc) with sort(field, Asc | Desc), preserving existing index behavior.

Changes

  • Use a single sort function in @@index, @@unique, and @@textIndex, with model-aware field validation and completion.
  • Preserve the context required by nested function arguments in the shared PSL attribute framework.
  • Update regression tests, documentation, example schemas, and example migration snapshots.
  • Add app upgrade instructions for current schemas, migration snapshots, and documentation.

Why

A stable function name makes the field an explicit argument instead of generating a function signature for every model field.

Scope: MongoDB syntax only. Plain fields and wildcard syntax remain supported. The old syntax is rejected; null-ordering options are not added. SQL syntax is unchanged.

Validation

  • 331 Mongo authoring tests and 1,357 parser tests passed.
  • 59 language-server completion tests and 34 focused integration tests passed.
  • Four package typechecks, builds, and Biome checks passed.
  • No old sort syntax remains in examples; diff checks and upgrade-instruction coverage passed.
  • Example applications were not run end-to-end.

Summary by CodeRabbit

  • New Features
    • MongoDB index declarations support sort(field, Asc) and sort(field, Desc), with editor suggestions for fields and sort directions.
  • Bug Fixes
    • Index sorting now correctly handles mapped fields, compound indexes, and text indexes.
  • Documentation
    • Updated MongoDB index guidance and examples to use the supported sort syntax, and added instructions for updating existing schemas and migration snapshots.

@StevenMcClankerton
StevenMcClankerton requested a review from a team as a code owner October 7, 2026 12:31
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 75cc9347-f7c4-4deb-8543-dac946cf2e9a
📥 Commits

Reviewing files that changed from the base of the PR and between 78d1bbe and 91be32e.

📒 Files selected for processing (1)
  • upgrade-instructions/pending/mongo-index-sort-function/app/instructions.md

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


📝 Walkthrough

Walkthrough

MongoDB index declarations now specify sort direction with sort(field, direction). Parser typing and interpretation, language-server completion tests, documentation, integration tests, upgrade instructions, and MongoDB examples reflect this syntax.

Changes

MongoDB index sort syntax

Layer / File(s) Summary
Function-call context typing
packages/1-framework/2-authoring/psl-parser/src/attribute-spec/*, packages/1-framework/2-authoring/psl-parser/src/binder.ts, packages/1-framework/2-authoring/psl-parser/test/attribute-spec-func-call-context.test-d.ts
Function-call signatures carry context types through their parameter and return types. Type tests cover string, model-field, and referenced-field arguments.
Index sort specification and interpretation
packages/2-mongo-family/2-authoring/contract-psl/src/*, packages/2-mongo-family/2-authoring/contract-psl/test/*, packages/2-mongo-family/2-authoring/contract-psl/README.md
Index specifications accept field references, wildcard calls, and sort(field, direction) calls. The interpreter resolves sort fields, maps directions, and handles nested paths. Tests cover normalized keys, mapped fields, and diagnostics.
Completion and syntax adoption
packages/1-framework/3-tooling/language-server/test/completion-provider.test.ts, test/integration/test/mongo/migration-psl-authoring.test.ts, examples/mongo-blog-leaderboard/*, examples/mongo-demo/*, examples/retail-store/*, upgrade-instructions/pending/mongo-index-sort-function/app/instructions.md
Completion tests cover sort-call arguments and field suggestions. Integration tests and example contracts use the positional sort syntax. Documentation and upgrade instructions describe the syntax change.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: aqrln

Merge Risk: ⚪ Minimal · up to 91be3

This change documents how to update MongoDB index sort syntax, with no merge-blocking risk identified.

Architecture Summary

Architecture risk: 🔵 Low · up to 91be3

The change affects 5 systems.

Changed systems: examples, packages/2-mongo-family, packages/1-framework, test, upgrade-instructions

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — examples (service) was modified; 9 changed files map to changed impact.
  • observed — packages/2-mongo-family (library) was modified; 6 changed files map to changed impact.
  • observed — packages/1-framework (library) was modified; 5 changed files map to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in examples/mongo-blog-leaderboard/README.md: The documented time-ordered index changes from @@index([createdAt(sort: Desc)]) to @@index([sort(createdAt, Desc)]); the syntax note is updated to identify the function form as supported and the per-field form as unsupported.
  • observed — Modified behavior in examples/mongo-blog-leaderboard/src/contract.prisma: The Post model’s descending createdAt index changes from the createdAt(sort: Desc) form to sort(createdAt, Desc).
  • observed — Modified behavior in examples/mongo-demo/migrations/app/20260626T1916_add_posts_indexes/contract.prisma: The Post index now expresses descending order with sort(createdAt, Desc) instead of createdAt(sort: Desc); authorId remains in the index.
  • observed — Modified behavior in examples/mongo-demo/src/contract.prisma: The Post index declaration changes its descending-sort syntax from createdAt(sort: Desc) to sort(createdAt, Desc); authorId remains the second indexed field.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 11 files. (1 skipped: 1… 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 primary change: replacing MongoDB PSL index syntax with sort(field, direction).
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 11 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

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

@prisma/orm-extension-middleware-cache

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

@prisma/orm-extension-paradedb

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

@prisma/orm-extension-pgvector

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

@prisma/orm-extension-postgis

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

@prisma/orm-extension-supabase

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

@prisma/orm-family-mongo

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

@prisma/orm-family-sql

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

@prisma/orm-framework

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

@prisma/orm-mongo

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

@prisma/orm-postgres

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

@prisma/orm-sqlite

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

@prisma/orm-target-mongo

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

@prisma/orm-target-postgres

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

@prisma/orm-target-sqlite

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

@prisma/orm-toolchain

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

commit: 91be32e

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 228.04 KB (0%)
postgres / emit 204.66 KB (0%)
mongo / no-emit 199.09 KB (-0.03% 🔽)
mongo / emit 177.16 KB (0%)
cf-worker / no-emit 285.84 KB (0%)
cf-worker / emit 259.77 KB (0%)

@SevInf
SevInf enabled auto-merge October 7, 2026 15:23
@SevInf
SevInf added this pull request to the merge queue Oct 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 8, 2026
@SevInf
SevInf added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit 185dfdc Oct 8, 2026
24 checks passed
@SevInf
SevInf deleted the sort-fn-index branch October 8, 2026 09:55
wmadden-electric added a commit that referenced this pull request Oct 8, 2026
Assemble their upgrade notes into the rc.16 to rc.17 guides, archive the originals, and add both PRs to the release notes and CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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