Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

TML-2790: M:N SQLite demo examples + project plan expansion (slices 4–6) - #742

Merged
aqrln merged 19 commits into
mainfrom
tml-2790-mn-demo-examples
Jun 18, 2026
Merged

aqrln merged 19 commits into
mainfrom
tml-2790-mn-demo-examples

Conversation

@tensordreams

@tensordreams tensordreams commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #697 — that PR was auto-marked merged by GitHub when a botched force-push briefly made its head identical to its base (nothing was actually merged; the branch content is unchanged). Same commits, same review state.

Follow-on to the SQL ORM: Many-to-Many End to End project: M:N demo examples + the project-plan expansion they surfaced.

Stacked PR — top of the M:N stack: tml-2787 (#683) → … → tml-2729 (#667) → main (the whole stack is rebased onto the latest main).

SQLite demo M:N examples (72ef8b793, 883309ecc)

The SQLite demo (examples/prisma-next-demo-sqlite, TS-authored) now demonstrates the full M:N ORM API via a pure Post ↔ Tag junction (PostTag):

  • Read: get-post-tags — .include(tags, t => t.select(...)).
  • Filter: get-posts-by-tag-filter — .where(p => p.tags.some/none/every(t => t.label.eq(...))).
  • Write (callback mutator): connect-post-tags / disconnect-post-tags / create-post-with-tags — .update/.create({ tags: t => t.connect/disconnect/create([...]) }) with readback.

Wired as 6 CLI commands + seed; smoke-tested end-to-end (SQLite is offline-runnable); emitted contract carries cardinality:N:M + through; emit:check + typecheck clean.

Why only SQLite (and the plan expansion) (d711adfb6)

Adding examples surfaced a real gap: the navigable M:N API is authorable only via the TS contract builder (rel.manyToMany), not PSL — PSL emits only 1:N/N:1 and routes M:N to explicit junction models. The PG demo emits from PSL, so it cant show M:N until PSL learns to author it. So:

  • Filed TML-2794 — PSL many-to-many authoring (the framework gap).
  • Filed TML-2795 — PG demo M:N examples + pre-existing dual-mode contract drift (blocked by TML-2794).
  • Amended the project spec + plan with follow-on slices 4–6 (SQLite examples [done], PSL M:N authoring [planned], PG demo [planned]) + slice specs/plans. Slice 5 is framework-scoped and flagged for possible promotion to its own project.

Scope / notes

This PR ships the SQLite examples + the planning docs only. PG demo examples + PSL authoring are tracked (TML-2794/2795) and specd but not implemented here. No production src/ changes — demo + project-docs only.

Refs: TML-2790.

Summary by CodeRabbit

Release Notes

  • New Features

    • Expanded the sqlite demo to support Post ↔ Tag many-to-many tagging via a junction.
    • Added CLI commands to query posts/tags, apply tag filters (some/none/every), and connect/disconnect or create posts with tags.
  • Documentation

    • Updated the demo README to cover the full many-to-many API, command behaviors, and junction insert/delete notes.
    • Enhanced seeding instructions and the seed process to create tags and junction rows.

@tensordreams
tensordreams requested a review from a team as a code owner June 5, 2026 15:04
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 49e92f72-09fb-420d-983a-03c0fe1a0917

📥 Commits

Reviewing files that changed from the base of the PR and between 5102cbf and 087a437.

📒 Files selected for processing (1)
  • examples/prisma-next-demo-sqlite/README.md
✅ Files skipped from review due to trivial changes (1)
  • examples/prisma-next-demo-sqlite/README.md

📝 Walkthrough

Walkthrough

Adds a full Post ↔ Tag many-to-many relation to the prisma-next-demo-sqlite example. This includes updating the contract definition, regenerating contract.json and contract.d.ts, expanding the seed script to insert tags and junction rows, adding seven ORM-client helper modules, wiring them into the CLI dispatcher, and updating the README and upgrade notes.

Changes

Post↔Tag Many-to-Many Demo

Layer / File(s) Summary
Contract definition and generated artifacts
examples/prisma-next-demo-sqlite/prisma/contract.ts, examples/prisma-next-demo-sqlite/src/prisma/contract.json, examples/prisma-next-demo-sqlite/src/prisma/contract.d.ts
Adds Tag and PostTag models to the source contract, wires the Post.tags N:M relation through post_tag, and regenerates both the JSON contract and TypeScript declaration file with new domain models, storage tables, field type maps, roots, and updated SHA256 hashes.
Seed script with tags and junction rows
examples/prisma-next-demo-sqlite/scripts/seed.ts
Refactors post insertion to use returning() to capture IDs, adds insertion of three Tag rows with validation, and inserts post_tag junction rows linking posts to tags.
ORM-client read helpers
examples/prisma-next-demo-sqlite/src/orm-client/get-post-tags.ts, examples/prisma-next-demo-sqlite/src/orm-client/get-tag-posts.ts, examples/prisma-next-demo-sqlite/src/orm-client/get-posts-by-tag-filter.ts
Adds ormClientGetPostTags, ormClientGetTagPosts, and ormClientGetPostsByTagFilter (supporting some/none/every modes) to query the N:M relation in both directions and apply relation-existence filters.
ORM-client mutation helpers
examples/prisma-next-demo-sqlite/src/orm-client/connect-post-tags.ts, examples/prisma-next-demo-sqlite/src/orm-client/disconnect-post-tags.ts, examples/prisma-next-demo-sqlite/src/orm-client/create-post-with-tags.ts, examples/prisma-next-demo-sqlite/src/orm-client/create-post-connect-tags.ts
Adds four helpers covering junction connect, junction disconnect, nested post+tag creation via t.create(), and post creation with existing-tag linking via t.connect().
CLI dispatcher wiring
examples/prisma-next-demo-sqlite/src/main.ts
Imports all new ORM-client helpers and extends main() with command branches for post-tags, tag-posts, posts-with-tag-{some,none,every}, connect-post-tags, disconnect-post-tags, create-post-with-tags, and create-post-connect-tags, including argument validation and JSON output.
README and upgrade notes
examples/prisma-next-demo-sqlite/README.md, skills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md
Updates the demo README with M:N CLI commands, a command-operation table, and pure-junction semantics explanation; adds a TML-2790 entry to the 0.14→0.15 upgrade notes describing the additive change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • prisma/prisma-next#680: The main PR's demo adds/uses Post.tags many-to-many relation filters (some/none/every) over the PostTag junction (e.g., get-posts-by-tag-filter.ts and related CLI/README examples), which directly relies on the core junction-aware some/none/every lowering implemented in the retrieved PR.

Suggested reviewers

  • aqrln

Poem

🐰 Hop, hop through the junction rows,
Posts and Tags now friends, as the schema grows!
connect, disconnect, create with glee,
A many-to-many dance for thee.
The bunny re-emits the hash anew,
No user action needed — just review! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main change: adding Many-to-Many (M:N) SQLite demo examples with Post ↔ Tag relation and accompanying project plan expansion for slices 4–6.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2790-mn-demo-examples

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.

❤️ Share

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

@github-actions

github-actions Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 154.55 KB (0%)
postgres / emit 142.13 KB (0%)
mongo / no-emit 78 KB (0%)
mongo / emit 72.09 KB (0%)
cf-worker / no-emit 181.82 KB (0%)
cf-worker / emit 167.78 KB (0%)

@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@742

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@742

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@742

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@742

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@742

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@742

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@742

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@742

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@742

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@742

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@742

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@742

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@742

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@742

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@742

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@742

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@742

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@742

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@742

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@742

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@742

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@742

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@742

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@742

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@742

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@742

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@742

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@742

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@742

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@742

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@742

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@742

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@742

prisma-next

npm i https://pkg.pr.new/prisma-next@742

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@742

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@742

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@742

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@742

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@742

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@742

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@742

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@742

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@742

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@742

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@742

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@742

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@742

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@742

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@742

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@742

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@742

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@742

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@742

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@742

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@742

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@742

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@742

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@742

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@742

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@742

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@742

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@742

commit: 087a437

@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 16dc690 to f3a7a5c Compare June 8, 2026 10:19
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from 1e62c8e to dbaf95a Compare June 8, 2026 10:19
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from f3a7a5c to b772b54 Compare June 8, 2026 11:19
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch 2 times, most recently from e19ee4a to 074d298 Compare June 8, 2026 14:46
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from b772b54 to 0f9d0c2 Compare June 8, 2026 14:46
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from 074d298 to ce2608d Compare June 8, 2026 16:45
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 0f9d0c2 to 2a360f4 Compare June 8, 2026 16:45
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from ce2608d to ac1c05d Compare June 9, 2026 11:07
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 2a360f4 to 67fb93c Compare June 9, 2026 11:07
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from ac1c05d to a5f259c Compare June 9, 2026 16:37
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch 2 times, most recently from 9feb292 to facaadf Compare June 9, 2026 16:39
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from a5f259c to 9829a58 Compare June 9, 2026 16:39
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from facaadf to 679770d Compare June 9, 2026 16:53
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from 9829a58 to 79ebfd0 Compare June 9, 2026 16:53
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 679770d to 302e804 Compare June 9, 2026 17:21
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch 2 times, most recently from 20e4a68 to 7774dfc Compare June 10, 2026 14:26
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 302e804 to 100b1d5 Compare June 10, 2026 14:26
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from 7774dfc to cef9592 Compare June 10, 2026 15:26
@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 100b1d5 to 91b8cc4 Compare June 10, 2026 15:26
@tensordreams

Copy link
Copy Markdown
Contributor Author

Reviewed this PR separately against tml-2787-slice-3-write (origin/tml-2787-slice-3-write...origin/tml-2790-mn-demo-examples). I focused on the SQLite demo command wiring, handwritten ORM modules, seed data, generated contract consistency, migration refs, and upgrade note placement. I did not find actionable issues in this PR. Verification while reviewing: pnpm --filter prisma-next-demo-sqlite typecheck, pnpm --filter prisma-next-demo-sqlite emit:check, and git diff --check for this PR diff all passed.

@tensordreams tensordreams left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against projects/sql-orm-many-to-many/slices/04-sqlite-demo-examples/spec.md; ran pnpm -C examples/prisma-next-demo-sqlite typecheck and emit:check locally (both pass).

Solid, well-scoped PR: the new ORM-client modules are idiomatic and cleanly demonstrate the full M:N surface (include, some/none/every, connect/disconnect, nested create), castAs is used at branded-id boundaries with no bare as or any in the new files, the CLI wiring matches the existing command style exactly (usage errors, exit codes, JSON output), and the planning docs for slices 4–6 are internally consistent with correct ticket references. The upgrade note correctly lives only in the 0.13→0.14 cycle with no leftover in 0.12→0.13.

One issue should be resolved before merge: the newly committed migrations/app/refs/ snapshot is stale against the re-emitted contract (old canonical shape, mismatched storage hash) — see inline. Everything else is polish.

@tensordreams
tensordreams force-pushed the tml-2787-slice-3-write branch from 91b8cc4 to 4ea74ff Compare June 10, 2026 18:15
…N examples

The new main baseline (TML-2605) trips the no-bare-cast ratchet on the
string->branded-id casts in the M:N example helpers (+10). Replace the
bare `as PostId`/`as TagId` casts with castAs<T> to keep lint:casts at
delta 0. Behaviour unchanged (casts are erased at runtime).

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
… models (TML-2807 rebase)

The post_tag and tag models added by this branch were emitted before
main emitted SqlModelStorage.namespaceId (TML-2807); re-emit so the
demo contract matches a fresh emit.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
…t<->Tag through

The through descriptor now carries the junction's namespaceId; re-emit
the demo contract so both M:N relations declare it.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
…r upgrade instructions

The check:upgrade-coverage gate requires every PR whose diff touches
examples/ to also touch the in-flight user-skill instructions. The M:N
demo additions need no user-side action (additive), so no new changes[]
entry — the existing array stays; this records the incidental diff.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
0.13.0 shipped without the M:N ORM-client examples, so the user-upgrade
note belongs in a new 0.13→0.14 instructions directory, not the
now-released 0.12→0.13 doc. The upgrade-coverage gate targets 0.13→0.14
after the release bump.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
Main renamed the char(36) uuid authoring helpers to make storage explicit
(field.uuid -> field.uuidString, field.id.uuidv4 -> field.id.uuidv4String).
The pre-existing User/Post models were migrated on main; the M:N models
added on this branch still called the old names, failing contract emit.
Emitted contract is unchanged (same storage semantics, no hash drift).

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
Close the two coverage gaps against the shipped M:N runtime: a reverse-
direction include (tag-posts, db.Tag.include("posts")) and connect inside
the create flow (create-post-connect-tags). Document the M:N commands in
the README, including a prose note on the required-payload junction guard,
which has no runnable example by design (the type gate makes it
uncompilable). All 9 M:N commands smoke-tested end-to-end on a fresh
database.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
…refs

Rebase onto the slice-3 namespace change (ExecutionMutationDefault.ref now
carries a namespace); regenerate the demo contract so its execution defaults
match the new shape.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
Slice 3 merged, so main now carries the 0.14-to-0.15 upgrade directory. With main
at 0.14.0 the in-flight transition is 0.14→0.15: move the TML-2790 demo-examples
note out of the released 0.13-to-0.14 cycle and into 0.14-to-0.15 (incidental,
additive demo material), so the per-PR upgrade-coverage declaration lands in the
directory the gate expects.

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
@tensordreams
tensordreams force-pushed the tml-2790-mn-demo-examples branch from 5822c1a to b566f6b Compare June 17, 2026 14:20
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

The connect and disconnect ORM-client examples issued a mutation
followed by a separate include read-back. The nested-mutation update
path already reloads the parent row through the read dispatch honoring
the configured `.include()`, so chaining `.include()` before
`.update()` returns the post with its tags in one query.

Verified: SQLite demo typecheck, lint, and emit:check pass; ran the
connect and disconnect commands against a seeded DB and confirmed the
returned post carries its ordered, id+label-projected tags.

Claude-Session: https://claude.ai/code/session_01XcWuDhwCq2tXf5W4Py1Mk6
Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/prisma-next-demo-sqlite/src/main.ts (1)

25-41: ⚡ Quick win

Remove the duplicated command catalog comment block from this TS file.

This section duplicates runtime usage/help content and will drift over time; the command behavior is already self-documenting via handlers and usage output.
As per coding guidelines, **/*.{ts,tsx,js,jsx,mts,mjs}: "Don't add comments if avoidable, prefer code that expresses its intent."

🤖 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-sqlite/src/main.ts` around lines 25 - 41, The
comment block describing the command catalog (lines 25-41) in the main.ts file
duplicates runtime usage documentation and will drift over time as the code
evolves. According to coding guidelines, avoid comments when code can be
self-documenting. Remove the entire multi-line comment block that describes the
Many-to-many commands, tag-related operations, and other command descriptions,
as the actual command behavior is already documented through the handlers and
runtime usage output in the code.

Source: Coding guidelines

🤖 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-sqlite/README.md`:
- Around line 36-43: Add runnable command examples for the missing filter
variants in the "Many-to-many (ids are printed by the seed)" section of the
README.md file. After the existing `posts-with-tag-some typescript` example
line, insert two additional command lines following the same format to
demonstrate the `posts-with-tag-none` and `posts-with-tag-every` filters, using
the pattern: SQLITE_PATH=./demo.db pnpm start -- <command-name> <argument>. This
ensures all three supported filter variants (some, none, every) are documented
as runnable examples.

---

Nitpick comments:
In `@examples/prisma-next-demo-sqlite/src/main.ts`:
- Around line 25-41: The comment block describing the command catalog (lines
25-41) in the main.ts file duplicates runtime usage documentation and will drift
over time as the code evolves. According to coding guidelines, avoid comments
when code can be self-documenting. Remove the entire multi-line comment block
that describes the Many-to-many commands, tag-related operations, and other
command descriptions, as the actual command behavior is already documented
through the handlers and runtime usage output in the code.
🪄 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: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ba5e4fc7-c3c8-4154-a9a7-37f690dc9393

📥 Commits

Reviewing files that changed from the base of the PR and between c793885 and 5102cbf.

⛔ Files ignored due to path filters (7)
  • projects/sql-orm-many-to-many/plan.md is excluded by !projects/**
  • projects/sql-orm-many-to-many/slices/04-sqlite-demo-examples/spec.md is excluded by !projects/**
  • projects/sql-orm-many-to-many/slices/05-psl-many-to-many-authoring/plan.md is excluded by !projects/**
  • projects/sql-orm-many-to-many/slices/05-psl-many-to-many-authoring/spec.md is excluded by !projects/**
  • projects/sql-orm-many-to-many/slices/06-pg-demo-examples/plan.md is excluded by !projects/**
  • projects/sql-orm-many-to-many/slices/06-pg-demo-examples/spec.md is excluded by !projects/**
  • projects/sql-orm-many-to-many/spec.md is excluded by !projects/**
📒 Files selected for processing (14)
  • examples/prisma-next-demo-sqlite/README.md
  • examples/prisma-next-demo-sqlite/prisma/contract.ts
  • examples/prisma-next-demo-sqlite/scripts/seed.ts
  • examples/prisma-next-demo-sqlite/src/main.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/connect-post-tags.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/create-post-connect-tags.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/create-post-with-tags.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/disconnect-post-tags.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/get-post-tags.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/get-posts-by-tag-filter.ts
  • examples/prisma-next-demo-sqlite/src/orm-client/get-tag-posts.ts
  • examples/prisma-next-demo-sqlite/src/prisma/contract.d.ts
  • examples/prisma-next-demo-sqlite/src/prisma/contract.json
  • skills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md

@aqrln
aqrln added this pull request to the merge queue Jun 18, 2026
@aqrln
aqrln removed this pull request from the merge queue due to a manual request Jun 18, 2026
The runnable command list showed only `posts-with-tag-some`, while the
CLI dispatches `-some`, `-none`, and `-every` and the runtime usage
string already lists all three. Add the two missing lines so the README
matches the implemented commands.

Claude-Session: https://claude.ai/code/session_01XcWuDhwCq2tXf5W4Py1Mk6
Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
@tensordreams

Copy link
Copy Markdown
Contributor Author

Thanks! Addressed the README finding (087a437). On the main.ts nitpick — keeping the top-of-file command catalog. This is a demo entry point where an at-a-glance map of every command is deliberately pedagogical, and a human reviewer already signed off on it. I take the drift point (the README list had in fact gone stale), but the fix there is to keep the docs current rather than drop the in-file overview, so I'm leaving the comment block as-is.

@aqrln
aqrln added this pull request to the merge queue Jun 18, 2026
Merged via the queue into main with commit 269e4be Jun 18, 2026
28 of 29 checks passed
@aqrln
aqrln deleted the tml-2790-mn-demo-examples branch June 18, 2026 14:30
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jul 12, 2026
…rough) (prisma#819)

**Slice 5 of the [SQL ORM: Many-to-Many End to
End](https://linear.app/prisma-company/project/sql-orm-many-to-many-end-to-end-c178df40ca3a)
project** (follow-on group). Refs TML-2794.

> **Stacked PR** — base is `tml-2790-mn-demo-examples` (prisma#742, slice 4);
below that `tml-2787-slice-3-write` (prisma#683) → `main`.

## Overview

PSL could not author a navigable many-to-many relation: the relation
resolver emitted only `N:1`/`1:N`, and a bare list field (`tags Tag[]`)
with no FK pair was diagnosed as `PSL_ORPHANED_BACKRELATION_LIST` —
`cardinality: 'N:M' + through` existed only via the TS contract builder.
This PR teaches the PSL interpreter **explicit-junction recognition**
(form 1, pinned at pickup): when a bare list field has a recognisable
junction model — composite `@@id([a, b])` covering exactly the FK
columns of two `N:1` relations to the two side models — the list lowers
to a navigable `N:M` relation through that junction, shape-identical to
`rel.manyToMany` output.

## Changes

- `psl-relation-resolution.ts`: junction recognition in the
previously-orphaned branch — `findJunctionFkPairs` + id-coverage gate +
`manyToManyRelationNode`; child FK must reference the target's **full
id** (set-equal), `through.childColumns` reordered to id order (the
runtime joins `childColumns[i] = targetColumns[i]` by index); decline →
existing orphaned diagnostic. Self-referential M:N disambiguated by the
list's `@relation` name (pins the parent-side FK); unnamed symmetric
lists get the ambiguity diagnostic. Surrogate-id join models are
deliberately not recognised. Direct FK matches still win (stay `1:N`).
- 10 lowering unit tests (`interpreter.relations.many-to-many.test.ts`):
both directions, composite keys, swapped-order FK references,
self-referential, diagnostic preservation, `validateContract`
round-trip.
- PSL-authored integration fixture `fixtures/mn-psl/` (`User ↔ Tag` via
`user_tags`, mirroring the TS fixture) wired into the sql-orm-client
emit pipeline so `fixtures:check` regenerates and diffs it.
- `mn-psl-parity.test.ts`: 8 integration tests proving the full M:N ORM
API (include explicit+implicit, `some`/`none`/`every`, connect,
disconnect, nested create) against the PSL-emitted contract.

## Why

The PG demo emits its contract from PSL, so it cannot show the M:N API
until PSL can author it (slice 6 is blocked on this). Form 1 was chosen
over Prisma-style implicit lists as the smallest surface that matches
the existing diagnostic's guidance; implicit lists remain a clean
follow-up.

## Scope

PSL authoring layer + fixtures/tests only. No sql-orm-client runtime
changes, no TS-builder changes, no demo changes (slice 6). Implicit-list
authoring (form 2) deliberately excluded.

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

* **New Features**
* Improved many-to-many backrelation lowering via explicit junction
models, including composite-key support and correct through/column
ordering.
* Enhanced FK/backrelation metadata to improve many-to-many resolution
across namespaces.

* **Bug Fixes / Improvements**
* Added richer diagnostics for orphaned, ambiguous, and invalid
many-to-many junction scenarios.
* Strengthened full SQL contract validation for N:M through
configurations (pairing, referenced column existence, and storage-type
consistency).

* **Tests**
  * Added unit tests for many-to-many lowering and diagnostics.
* Added integration parity coverage for includes, filters, and nested
writes using the mn-psl fixture.

* **Documentation / Chores**
* Updated Prisma Next emit flow and refreshed mn-psl fixture typing for
UUID-style IDs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Alexey Orlenko's AI Agent <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants