Repository navigation
TML-3008: differ pairs siblings by (nodeKind, id) — delete the role-sigil workaround - #952
Conversation
Substrate cleanup: the SQL schema differ pairs siblings by (nodeKind, id) instead of a globally-unique id, deleting the role-sigil workaround and withCleanRoleMessage. Lands ahead of #950's rebase. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Adds a nodeKind discriminant to DiffableNode so the generic schema differ (diffSchemas/diffChildren/insertNode) keys sibling nodes on (nodeKind, id) instead of a bare id, using a single delimiter-joined Map key so insertion-order iteration stays byte-identical. A same-id sibling pair with different nodeKind (e.g. a role and a namespace both named "public") now diffs without throwing; a genuine same-kind same-id duplicate still throws. Every SQL schema-IR node already declared nodeKind, so this is free there; Mongo schema-IR nodes gain a genuine per-node nodeKind literal alongside their existing kind field. Removes SchemaDiffIssue.message and the differs pathMessage helper — message was always just the joined path, so every real consumer (sqlite/postgres issue-planner conflict summaries, the CLI verify formatter, the sqlite recreate-table summary, and the hand-rolled Mongo diffMongoSchemas issues) now renders its own string from path/reason instead. Amends the schema-diff ADR to describe (nodeKind, id) keying and retracts its prior guidance to fold a node kind into its id string, which is what produced the role: sigil workaround this slice was cut to make unnecessary. The postgres role sigil (ROLE_ID_SIGIL) and withCleanRoleMessage never existed on this branch — it forked from before the role-in-verify work that introduced them, so those two files needed no changes; the existing PostgresRoleSchemaNode already returns the bare role name. Signed-off-by: Will Madden <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…row message Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
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 (7)
💤 Files with no reviewable changes (5)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSchema diff issues now contain structural data without generated messages. Sibling alignment uses ChangesSchema diff contract and alignment
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 📦
|
…ed duplicate Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Main (TML-3008, PR #952) shipped DiffableNode.nodeKind and pairs siblings by (nodeKind, id) rather than id alone, and deleted SchemaDiffIssue.message. PostgresRoleSchemaNode.id now returns the bare role name — a role and a same-named namespace no longer need a role: sigil to avoid colliding in the differ, since nodeKind already disambiguates them. withCleanRoleMessage (which stripped that sigil out of issue.message) is deleted along with it; consumers now read reason/path off the issue instead of a rendered message. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
….message #952 removed `message` from `SchemaDiffIssue` (the differ no longer stamps a default path string). `mapNativeEnumNodeIssue` still read `issue.message` for its no-schema conflict text; render `issue.path.join(/)` instead, the same way every other conflict in this file already names its issue. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Linked issue
Refs TML-3008
Unblocks #950 (TML-2870), which rebases onto this and deletes its
role:-sigil workaround.At a glance
Before this PR the differ keyed a parent's children into one flat map on bare
idand threwdiffSchemas: duplicate id among siblingson any collision — so a Postgres role namedpublicand a schema namedpublic, which are different objects that never pair against each other, could not coexist as siblings in the diff tree.Decision
Two things:
(nodeKind, id), not by a globally-uniqueid.DiffableNodegainsreadonly nodeKind: string— the per-node discriminant every SQL schema-IR node already declares, so the SQL tree satisfies it with zero changes. Anidnow only needs to be unique among same-kind siblings, which it already is by construction (you can't declare two roles namedpublic, or two columns namedidon one table). A node never folds its kind into its id string to route around the differ.SchemaDiffIssue.messageis deleted. The differ reports structured data (path,reason, the nodes); turning that into a human sentence is the renderer's job. Every producer that baked prose intomessage— including Mongo's hand-rolleddiffMongoSchemas— stops; every consumer renders frompath/reasonitself.Reviewer notes
Mapkeyed on`${nodeKind}\u0000${id}`— deliberately not a nested per-kind map — so insertion order, and therefore emitted-issue order, is bit-for-bit what it was. EverynodeKindin the repo is a code-defined literal, so the NUL delimiter cannot collide. The only input whose behavior changes is one that previously threw (cross-kind sibling id collision); no previously-succeeding diff changes output. Zero fixture/snapshot/golden files changed in this PR.db verifyfailure text becomes path-based.diffMongoSchemasused to bake sentences likeCollection "users" is missing from the databaseintomessage; issues now render asusers/orders/validatorwith thereasonlabel. Accepted deliberately — no committed snapshot pinned the prose, and a follow-up renderer can rebuild richer text from the structured issue when wanted.messagesweep is most of the diff. The keying change itself is ~40 lines; the other ~30 files are consumers and test literals that carriedmessage. One consumer was missed on the first pass and caught by review: the CLI error-envelope formatter printed blank issue bodies for SQLite/Mongo verify failures (errors.ts now rendersmessage ?? path.join('/'), since PSL diagnostics share that envelope and legitimately carrymessage).projects/postgres-rls/slices/differ-kind-keying/) are committed for review context and are cleaned up at project close-out, per this repo's Drive convention.How it fits together
DiffableNode.nodeKindis an opaque string — no target vocabulary enters the framework. SQL nodes inherit it fromSqlSchemaIRNode's existing abstractnodeKind; the five Mongo schema-IR nodes each gain a genuine per-node literal (collection,index,validator,collectionOptions,schema) matching their existingkinddiscriminators 1:1.insertNode/diffChildrenbuild the sibling map on the combined key and throw only on a genuine same-kind/same-id duplicate (schema-diff.ts).pathMessageandSchemaDiffIssue.messageare deleted; consumers that need a string build it frompath— the CLI verify formatter,db verify, the sqlite/postgres issue planners' conflict summaries, and the CLI error-envelope formatter.id()(the guidance that produced tml-2870: author RLS policies for every operation, and verify declared roles exist #950's sigil).Behavior changes & evidence
public/namespace-publicpair independently; same-kind/same-id still throws; issues carry nomessage).nodeKind; the Mongo diff algorithm is otherwise unchanged apart from droppingmessage. Implementation: schema-node.ts, schema-diff.ts. Evidence: cli.control-policy.mongo.e2e.test.ts.Testing performed
pnpm build(68/68), forcedpnpm typecheck(143/143),pnpm lint+pnpm lint:depson touched packagespnpm test:packages(12k+ tests),pnpm test:integration,pnpm test:e2e(109/109)pnpm fixtures:check— clean;git statusafter: no fixture/snapshot/golden file changed/varsymlink, sql-orm-client portal race (both known families, untouched files)Follow-ups
role:sigil +withCleanRoleMessage(TML-2870).Alternatives considered
role:sigil). Rejected — it re-encodes lost structural information into a name, then leaks into paths and needs laundering (withCleanRoleMessage). That workaround is what tml-2870: author RLS policies for every operation, and verify declared roles exist #950 currently ships and deletes after this merges.EntityCoordinate. Rejected (and the ADR's original rejection stands) — schema-IR-node identity is its own domain; mapping a schema-IR node to a contract coordinate is a separate consumer-side operation, not the diff walk's concern.Map<nodeKind, Map<id, node>>. Rejected — regrouping by kind changes iteration order and would break emitted-issue byte-identity; the single combined-key map preserves insertion order exactly.messagepopulated with the path string. Rejected — it duplicatespathas a pre-rendered string and invites producers (as Mongo did) to bake presentation into data the renderer should own.Checklist
Signed-off-by)TML-XXXX: <sentence case>conventionSummary by CodeRabbit
Bug Fixes
Refactor
nodeKindinstead ofkindfor type discrimination.