TML-2795: M:N slice 6 — PG demo M:N examples - #820
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR updates the prisma-next-demo initial migration artifacts for UUID identifiers, Priority, Tag/PostTag, and Task polymorphism. It removes superseded migration files, adds tag ORM and CLI flows, updates seeding, and expands the README with many-to-many examples. ChangesSchema, migration artifacts, and demo tag flows
Sequence Diagram(s)sequenceDiagram
participant main.ts
participant helper as ormClientConnectPostTags
participant orm as createOrmClient
participant db as Postgres
main.ts->>helper: postId, tagIds, runtime
helper->>orm: createOrmClient(runtime)
orm->>db: find Post by id
helper->>db: connect/disconnect tags
db-->>helper: updated post
helper-->>main.ts: JSON result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/config-loader
@prisma-next/emitter
@prisma-next/language-server
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
8d27a89 to
ffd4829
Compare
872c0ac to
1c43446
Compare
ffd4829 to
d89a2f4
Compare
1c43446 to
564ebc0
Compare
d89a2f4 to
382c349
Compare
96a2c6f to
3903f46
Compare
382c349 to
bf39877
Compare
3903f46 to
23d1440
Compare
bf39877 to
ea1eb5d
Compare
23d1440 to
389209a
Compare
ea1eb5d to
856ac15
Compare
389209a to
643be8b
Compare
856ac15 to
f5dd02e
Compare
643be8b to
9c981ce
Compare
f5dd02e to
c5add23
Compare
9c981ce to
153e30a
Compare
c5add23 to
06419ec
Compare
153e30a to
03a7a8b
Compare
06419ec to
bd43c38
Compare
03a7a8b to
7d71303
Compare
47316a3 to
23675e5
Compare
…refs Rebase onto the slice-3 namespace change: regenerate the pg demo contract and the add_post_tags migration snapshot so their execution-default refs carry the namespace. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
Rebase onto main brought the enum-becomes-domain-concept refactor and the op-factory-to-method migration API. Update the add_post_tags migration: its contract.prisma snapshot adopts the domain-enum syntax (enum + @@type, enum2 -> enum) to match the regenerated demo chain, and migration.ts moves the bare createIndex/addForeignKey factories to this.createIndex/ this.addForeignKey. Regenerate the demo contract + migration chain. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
…se onto 0.14.0 main Rebasing onto main picked up TML-2916 (un-namespaced PG models default to `public`, dropping the empty `__unbound__` storage slot). Re-emit the demo contract and regenerate the `add_post_tags` M:N migration so they match the new emitter output; storage/migration hashes update and the chain stays consistent. Lockfile drops the demo's `@prisma-next/sql-contract-ts` dependency (the demo is now PSL-only). Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
…arity The N:M through-consistency validator (TML-2794 slice 5) requires junction columns to share the storage type of the id they reference. The PG demo declared uuid ids (`String @default(uuid())` -> char(36)) with plain `String` junction FKs (-> text), so post_tag.{postId,tagId} did not match post.id/tag.id. Switch every uuid column (ids and FKs) to a shared `Uuid = String @db.Uuid` so they all emit native `uuid` consistently, and collapse the demo's migration chain into a single uuid-consistent baseline — the old snapshots encoded the pre-fix mismatch, which validateSqlContractFully rejects on historical contracts too. One offline test's hard-coded id codec assertion updated (sql/char@1 -> pg/uuid@1). Claude-Session: https://claude.ai/code/session_01XcWuDhwCq2tXf5W4Py1Mk6 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
Rebase onto main brought TML-2929/2928 (CST parser + formatter), whose emitter formats the generated contract.d.ts slightly differently for the pgvector codec type. Re-emit the demo contract.d.ts and the baseline migration's end-contract.d.ts so emit:check / fixtures:check stay clean. No contract.json change. Claude-Session: https://claude.ai/code/session_01XcWuDhwCq2tXf5W4Py1Mk6 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
….14→0.15 Slice 6 touches `examples/prisma-next-demo/**` to demonstrate the new Post<->Tag many-to-many, which trips the `check-upgrade-coverage` per-PR gate: a PR touching examples/ must record a deliberate declaration in the in-flight `0.14-to-0.15/instructions.md`. The diff is an additive demonstration of slice 5's many-to-many authoring surface — no consumer contract changes shape and no migration is forced — so record it as an incidental substrate diff (`changes: []`) with an explanatory comment, matching the established pattern. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
d86d1a6 to
df501d2
Compare
… PSL parity Slice 6 originally reconciled the demo's pre-existing dual-mode contract drift by deleting the TypeScript contract source and the no-emit workflow, making the demo PSL-only. That removed the only demonstration of the no-emit / inline-TS-contract workflow. Restore them as-is from main: the TS contract source (prisma/contract.ts), its emit config (prisma-next.config.ts-contract.ts), the no-emit CLI + queries + runtime, and the dual-mode test scripts plus the TS-leg test files. The slice's M:N additions are kept (PSL Post<->Tag relation, native uuid ids, ORM examples, CLI commands, seed, integration tests) — the no-emit surface is left exactly as main had it, additive M:N only. The TS leg diverges from the PSL source (no discriminated Task/Bug/Feature hierarchy, no displayName/typed Address, no M:N, uuid-string vs native uuid), so `pnpm test:dual-mode` is red on the TS leg. This is tolerated because CI does not run it — CI runs typecheck:examples / lint:examples / test:examples, all of which are green (demo typecheck + lint clean, 65 tests pass). Real parity is tracked by TML-2938, blocked by TML-2228 (TS authoring DSL polymorphism support — the discriminated hierarchy cannot be authored in TypeScript until that lands). - README + App.tsx: restore the two-workflows / dual-mode narrative; the M:N sections are preserved. - upgrade 0.14->0.15 instructions: drop the now-inaccurate "PSL-only single-source" claim from the TML-2795 note. - slice spec: record the deferral and the TML-2938 / TML-2228 tracking. Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
|
On it — addressing the README client-signature note: |
…pdate query The M:N connect example issued two queries: an .update() that linked the tags, then a separate .select().include().first() to read the post back. The .include(...).update(...) chain returns the updated post with its tags in one query, so fold the read-back into the mutation. Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
…e+update query The M:N disconnect example issued two queries: an .update() that unlinked the tags, then a separate .select().include().first() to read the post back. The .include(...).update(...) chain returns the updated post with its remaining tags in one query, so fold the read-back into the mutation. Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
The Emit-Workflow paragraph documented `postgres<Contract, TypeMaps>({ contractJson, url })`,
but src/prisma/db.ts constructs the client with a single `Contract` type
parameter. Drop the second type parameter and the "Contract and TypeMaps"
wording so the README reflects what the demo actually does.
Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
Tag labels in the demo are conceptually unique (they're the human-facing identity of a tag), and the connect/disconnect examples treat them as such. Mark Tag.label @unique in both PSL sources (the app schema and the baseline migration's own contract.prisma), re-emit the contract, and regenerate the migration so the baseline CREATE TABLE adds the tag_label_key UNIQUE constraint. The migration's hand-authored operations carry the matching unique() constraint so the applied schema verifies against the contract. Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
The single-query include+update returns the full Post row by default; the
example demonstrates a projected read-back of just id, title, and the tag
list. Restore the explicit .select('id', 'title') in the chain so the
returned shape stays narrow.
Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
The single-query include+update returns the full Post row by default; the
example demonstrates a projected read-back of just id, title, and the
remaining tag list. Restore the explicit .select('id', 'title') in the
chain so the returned shape stays narrow.
Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
|
Done (README client signature) — |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/prisma-next-demo/README.md`:
- Around line 70-74: The README’s Markdown fence under the Usage section is
missing the required blank line before the fenced block, causing markdownlint
MD031 failures. Update the README content around the Usage example so the fenced
block is separated by blank lines from the preceding text, keeping the code
fence itself unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4e4f1239-8fab-4963-956b-8ca273f06c73
📒 Files selected for processing (15)
examples/prisma-next-demo/README.mdexamples/prisma-next-demo/migrations/app/20260422T0720_initial/contract.prismaexamples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.jsonexamples/prisma-next-demo/migrations/app/20260422T0720_initial/migration.jsonexamples/prisma-next-demo/migrations/app/20260422T0720_initial/migration.tsexamples/prisma-next-demo/migrations/app/20260422T0720_initial/ops.jsonexamples/prisma-next-demo/src/main.tsexamples/prisma-next-demo/src/orm-client/connect-post-tags.tsexamples/prisma-next-demo/src/orm-client/disconnect-post-tags.tsexamples/prisma-next-demo/src/prisma/contract.d.tsexamples/prisma-next-demo/src/prisma/contract.jsonexamples/prisma-next-demo/src/prisma/contract.prismaprojects/sql-orm-many-to-many/slices/06-pg-demo-examples/spec.mdskills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/prisma-next-demo/README.md`:
- Around line 70-74: The README’s Markdown fence under the Usage section is
missing the required blank line before the fenced block, causing markdownlint
MD031 failures. Update the README content around the Usage example so the fenced
block is separated by blank lines from the preceding text, keeping the code
fence itself unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4e4f1239-8fab-4963-956b-8ca273f06c73
📒 Files selected for processing (15)
examples/prisma-next-demo/README.mdexamples/prisma-next-demo/migrations/app/20260422T0720_initial/contract.prismaexamples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.jsonexamples/prisma-next-demo/migrations/app/20260422T0720_initial/migration.jsonexamples/prisma-next-demo/migrations/app/20260422T0720_initial/migration.tsexamples/prisma-next-demo/migrations/app/20260422T0720_initial/ops.jsonexamples/prisma-next-demo/src/main.tsexamples/prisma-next-demo/src/orm-client/connect-post-tags.tsexamples/prisma-next-demo/src/orm-client/disconnect-post-tags.tsexamples/prisma-next-demo/src/prisma/contract.d.tsexamples/prisma-next-demo/src/prisma/contract.jsonexamples/prisma-next-demo/src/prisma/contract.prismaprojects/sql-orm-many-to-many/slices/06-pg-demo-examples/spec.mdskills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md
🛑 Comments failed to post (1)
examples/prisma-next-demo/README.md (1)
70-74: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a blank line before the fenced block.
markdownlintis flagging this code fence (MD031), so the README will keep failing docs lint until the fence is surrounded by blank lines.Suggested fix
**Usage**: + ```bash # No emit step needed - just run the app pnpm start:no-emit -- users</details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion **Usage**:🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 71-71: Fenced code blocks should be surrounded by blank lines
(MD031, blanks-around-fences)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/prisma-next-demo/README.md` around lines 70 - 74, The README’s Markdown fence under the Usage section is missing the required blank line before the fenced block, causing markdownlint MD031 failures. Update the README content around the Usage example so the fenced block is separated by blank lines from the preceding text, keeping the code fence itself unchanged.Source: Linters/SAST tools
…031) The Setup and No-Emit Usage fenced blocks sat directly under their `**...**:` labels with no separating blank line, tripping markdownlint MD031 (blanks-around-fences). Add the blank line before each fence. Claude-Session: https://claude.ai/code/session_019LgHiD5BC7aHcjSmBkCQF2 Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
|
Done — fixed the markdownlint MD031 nit in |
Slice 6 of the SQL ORM: Many-to-Many End to End project. Refs TML-2795.
Overview
M:N examples.
Post ↔ Tagmany-to-many authored in PSL using slice 5's explicit-junction form (composite-@@idPostTag+ bare list fields on both sides), withTag.label@uniqueso the by-label API has a stable 1:1 lookup key. The demo's migrations are baselined into a single20260422T0720_initialsnapshot carrying the full schema (Post / Tag / PostTag with the composite junction PK, FK indexes + FKs, and the uniqueTag.label). All nine M:N surfaces from the SQLite demo are mirrored asrepo-*CLI commands: include in both directions,some/none/everyfilters (vacuous-trutheveryobservable via an untagged seed post), connect, disconnect, nested create, and connect-in-create. Seed adds tags + junction rows; README documents the commands and the required-payload-junction guard.Dual-mode / no-emit left as-is. The PG demo remains dual-mode (PSL
src/prisma/contract.prisma+ TSprisma/contract.ts+ the no-emit workflow). The TS contract builder cannot author the discriminatedTask/Bug/Featurehierarchy (nor M:N), sopnpm test:dual-modeis red on the TS leg — but it is not run by CI (CI runstypecheck:examples/lint:examples/test:examples, all green). Bringing the TS leg to parity and greening the dual-mode test is deferred to TML-2938, blocked by TML-2228 (TS authoring DSL polymorphism support). This PR is additive M:N only; the no-emit / dual-mode surface is unchanged frommain.Tests
8 PGlite-backed integration tests (
test/many-to-many.integration.test.ts) per the project standard: whole-shapetoEqual, explicitselectin most reads plus one implicit default-selection include, all three filter predicates, and include-readback after each of the four write kinds. Full demo suite green (12 files / 65 tests). Rootfixtures:checkandtypecheck:examplesgreen.Scope
examples/prisma-next-demoonly — no framework, PSL-interpreter, or sql-orm-client changes. With this slice, the M:N API is demonstrated in both demos and the project's follow-on scope is complete.Summary by CodeRabbit