Repository navigation
TML-2962: contract infer omits elements the stack's extension packs describe - #919
Conversation
…describes Redesigned on the #894 schema-node tree: the family instance passes the pack contract spaces (as-is, unmerged) into the target inferPslContract hook, and the inferrer skips tree tables the aggregate already declares, matched by (schemaName, tableName). Replaces the closed #901 approach (caller-computed claimed set over the retired flat SqlSchemaIR). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…lice G branch Carries the three doc changes from the closed docs-only PR #899, corrected to the settled Slice G design: G is no longer gated on Slice F (the mechanism subtracts whatever the pack contract spaces declare today; F only deepens what gets omitted), and C16 records the shaped ownership resolution (aggregate-in via the target inferPslContract hook) instead of "shaped at pickup". Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
The family instance passes the stack extension packs contract spaces as-is into the target inferPslContract hook; the Postgres inferrer skips tree tables an aggregate member already declares, matched by (schemaName, tableName) with namespaces matched on their id rather than record key. Omission happens before the cross-schema duplicate-name check, and foreign keys on surviving tables are dropped only when the referenced name was omitted and has no surviving table, so a legitimate same-named relation in another namespace is never stripped. Empty aggregate output is byte-identical. Co-Authored-By: Claude Fable 5 <[email protected]> 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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe SQL family now threads described extension contracts into Postgres PSL inference. Owned tables are omitted, cross-space foreign keys are rewritten or dropped, and shared coordinate keys plus tests and guidance were added. ChangesExtension-aware contract inference
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant SqlFamilyInstance
participant postgresTargetDescriptor
participant inferPostgresPslContract
participant PostgresSchema
SqlFamilyInstance->>SqlFamilyInstance: collect describedContracts from extension packs
SqlFamilyInstance->>postgresTargetDescriptor: inferPslContract(schemaIR, describedContracts)
postgresTargetDescriptor->>inferPostgresPslContract: inferPostgresPslContract(tree, describedContracts)
inferPostgresPslContract->>inferPostgresPslContract: compute owners from describedContracts
inferPostgresPslContract->>PostgresSchema: omit owned tables and rewrite foreign keys
inferPostgresPslContract-->>postgresTargetDescriptor: PslDocumentAst
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
size-limit report 📦
|
@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: |
…e extraction as TML-2977 Review found the implementation minted a parallel "aggregate" concept (SqlAggregateContractMember, SqlPslInferContext) and a table-specific membership test, duplicating machinery that already exists. Reshape the slice to reuse elementCoordinates (framework-components) for an entity-coordinate-generic, coordinate-precise match over the packs contract spaces — no new type, nothing added to migrations/types.ts. The deeper finding (ContractSpaceAggregate is the pure aggregation-of- contracts concept overfitted to the migration domain; the migration state should extend it) is filed as follow-on TML-2977, not built here. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ted aggregate types Reworks the omission to reuse framework-componentss elementCoordinates (the same coordinate walk the contract-space aggregate and cross-space collision check use) instead of a bespoke per-table membership test. The family forwards the packs already-assembled contracts through a widened inferPslContract hook param (readonly Contract<SqlStorage>[]); the inferrer builds a declared-coordinate set and omits any tree node whose (namespaceId, entityKind, entityName) coordinate is in it. Entity- agnostic and coordinate-precise; no new type, nothing added to migrations/types.ts. Deletes SqlAggregateContractMember, SqlPslInferContext, and isTableDescribedByAggregate. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
contract infer omits elements the aggregate contract describescontract infer omits elements the stack's extension packs describe
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
`@packages/3-targets/3-targets/postgres/src/core/psl-infer/infer-psl-contract.ts`:
- Around line 88-90: The coordinateKey helper in infer-psl-contract.ts is
collision-prone because it concatenates namespaceId, entityKind, and entityName
with spaces, so distinct coordinates can map to the same string. Update
coordinateKey to use a delimiter or encoding that cannot appear in quoted
identifiers, and make sure all call sites that compare or store these keys in
the PSL inference flow use the same unambiguous format.
🪄 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: 73fa3e9d-5ed0-46e4-af5f-89e276096955
⛔ Files ignored due to path filters (4)
projects/extension-supabase/plan.mdis excluded by!projects/**projects/extension-supabase/slices/g-extension-aware-infer/spec.mdis excluded by!projects/**projects/supabase-integration/decisions.mdis excluded by!projects/**projects/supabase-integration/deferred.mdis excluded by!projects/**
📒 Files selected for processing (6)
packages/2-sql/9-family/src/core/control-instance.tspackages/2-sql/9-family/src/core/migrations/types.tspackages/2-sql/9-family/test/psl-infer-described-contracts.test.tspackages/3-targets/3-targets/postgres/src/core/psl-infer/infer-psl-contract.tspackages/3-targets/3-targets/postgres/src/exports/control.tspackages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract-described-contracts.test.ts
| readonly inferPslContract?: (schema: SqlSchemaIRNode) => PslDocumentAst; | ||
| readonly inferPslContract?: ( | ||
| schema: SqlSchemaIRNode, | ||
| describedContracts?: readonly Contract<SqlStorage>[], | ||
| ) => PslDocumentAst; |
There was a problem hiding this comment.
Extract whatever interface this is attached to into a separate file, not types.ts
There was a problem hiding this comment.
Done in 323b56c1a. Extracted SqlControlTargetDescriptor (and the hook's own param type SqlDescribedContractSpace) into a new packages/2-sql/9-family/src/core/control-target-descriptor.ts. migrations/types.ts only lost declarations; the public @prisma-next/family-sql/control export path is unchanged.
| { | ||
| readonly inferPslContract?: ( | ||
| schema: SqlSchemaIRNode, | ||
| describedContracts?: readonly Contract<SqlStorage>[], | ||
| ) => PslDocumentAst; | ||
| }, |
There was a problem hiding this comment.
Use a real interface, not this nonsense inline type def
There was a problem hiding this comment.
Done in 323b56c1a. The anonymous inline structural type is gone — the hook is now read via a cast to the named SqlControlTargetDescriptor.
| /** | ||
| * Canonical key for an entity coordinate, joining the three axes | ||
| * `elementCoordinates` yields (namespace, entity kind, entity name). Entity- | ||
| * agnostic by construction: a table lives at `(schemaName, 'table', | ||
| * tableName)` today, but a pack-declared enum or policy reaching the tree | ||
| * later would key exactly the same way. | ||
| */ | ||
| function coordinateKey(namespaceId: string, entityKind: string, entityName: string): string { | ||
| return `${namespaceId} ${entityKind} ${entityName}`; | ||
| } |
There was a problem hiding this comment.
This function already exists in other places. Can we use a consistent implementation?
There was a problem hiding this comment.
Done in 323b56c1a. Extracted one collision-safe coordinateKey next to EntityCoordinate in @prisma-next/framework-components/ir (JSON-array encoding), now used by both this inferrer and check-integrity.ts (replacing its inline :-joined key). This also closes CodeRabbit's space-delimiter collision point.
… (review) Will's review: an app FK into pack-owned space (public.profile.userId -> auth.users) is a cross-space reference, not a dangling FK. PSL expresses it directly (supabase:auth.AuthUser @relation(...), per the shipped example). Replace the strip with resolution: use the FK's referencedSchema + the described contracts to resolve the owning spaceId and domain model name, emit the qualified <spaceId>:<namespace>.<Model> reference. Adds the headline cross-space FK integration test, a shared collision-safe coordinate-key helper, and the SqlControlTargetDescriptor extraction out of migrations/types.ts. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…criptor (PR #919 review) Addresses Will's review on #919: - Cross-space FKs: an app FK into pack-owned space (public.profile.userId -> auth.users) is resolved to the qualified relation supabase:auth.AuthUser (via the FK referencedSchema + the described contracts, reverse-looking-up the pack domain model), not stripped as "dangling". The pack-owned coordinate is matched schema-precise BEFORE the bare-name local check, so a same-named local table (public.users) never shadows it. Owned storage with no domain model throws instead of silently dropping. Genuinely-dangling FKs drop the relation, keep the scalar column. Proven end-to-end against a live PGlite Supabase-shim DB. - One shared collision-safe coordinateKey in framework-components, used by infer and check-integrity (replaces the space-join and the inline : key). - SqlControlTargetDescriptor extracted out of migrations/types.ts into its own file; the inline blindCast structural type replaced with the named descriptor. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…919 The PR touches packages/3-extensions/supabase (a new integration test + a psl-printer devDependency); check:upgrade-coverage requires a declaration. Incidental — no extension-author API changed. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
| export function coordinateKey( | ||
| coordinate: Pick<EntityCoordinate, 'namespaceId' | 'entityKind' | 'entityName'>, | ||
| ): string { | ||
| return JSON.stringify([coordinate.namespaceId, coordinate.entityKind, coordinate.entityName]); |
There was a problem hiding this comment.
I don't love serializing this as JSON. Can we not serialize it as eg [coordinate.namespaceId, coordinate.entityKind, coordinate.entityName].map(JSON.stringify).join('-')?
There was a problem hiding this comment.
Done in 36a8fd2f4 — coordinateKey now builds the key as [namespaceId, entityKind, entityName].map(JSON.stringify).join('-'). Still collision-safe (each component individually quoted). Unit test unchanged (it asserts collision behaviour, not the literal string) and green.
…eview)
Will's final review: build the key as
[namespaceId, entityKind, entityName].map(JSON.stringify).join(("-")) rather
than JSON.stringify([...]). Still collision-safe (each component is
individually quoted), just the preferred readable form.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe SQL family now threads described extension contracts into Postgres PSL inference. Owned tables are omitted, foreign keys into owned spaces are rewritten or dropped as needed, and related tests plus upgrade guidance were added. ChangesExtension-aware contract inference
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant SqlFamilyInstance
participant postgresTargetDescriptor
participant inferPostgresPslContract
participant PostgresSchema
SqlFamilyInstance->>SqlFamilyInstance: collect describedContracts from extension packs
SqlFamilyInstance->>postgresTargetDescriptor: inferPslContract(schemaIR, describedContracts)
postgresTargetDescriptor->>inferPostgresPslContract: inferPostgresPslContract(tree, describedContracts)
inferPostgresPslContract->>inferPostgresPslContract: compute owners from describedContracts
inferPostgresPslContract->>PostgresSchema: omit owned tables and rewrite foreign keys
inferPostgresPslContract-->>postgresTargetDescriptor: PslDocumentAst
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
Reconciles the one-differ-two-ir-planner slice (retired coordinate issue vocabulary, SchemaDiff/SchemaFindingLists collapse, SchemaOwnership) with main's #906 (native Postgres enums) and #919 (extension-aware contract infer). Conflicts in five files: - migrations/types.ts + control-target-descriptor.ts: main moved SqlControlTargetDescriptor into its own file and widened inferPslContract with describedContracts + SqlDescribedContractSpace; kept that move and re-applied our diff-hook reshape (diffDatabaseSchema/verifyDatabaseSchema -> diffSchemaForVerdict) plus the vocabulary retirement (verifyType returns SchemaDiffIssue, keepDiffIssue -> ownership). - exports/control.ts: kept both main's new control-target-descriptor export and our ColumnOpRenderer export. - control-instance.ts: kept both our verifySqlSchemaByDiff verify path and main's describedContracts threading; dropped main's verifyDatabaseSchema read (referenced the deleted coordinate hook). - infer-psl-contract.ts: kept main's resolveForeignKeys cross-space FK logic and constructed its rebuilt tables as real SqlTableIR instances (our slice made SqlTableIR a DiffableNode class, so main's plain-object clone no longer typed). - 0.14-to-0.15 upgrade instructions: kept every changes[] entry and narrative from both sides. Adapted main's #919 test (psl-infer-described-contracts.test.ts) to the required nodeKind/diffRole discriminants and dropped its stubs for the deleted descriptor hooks. pnpm install linked main's new @prisma-next/psl-printer devDep. Build 68/68, forced typecheck 143/143. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
What
contract infernow writes acontract.prismacontaining only what the stack's contract spaces don't already account for. When a stack extension pack's contract space declares a DB element (e.g. the Supabase pack's tables), the inferrer omits it — a brownfield app on top of an extension gets a contract of its own tables.Slice G of the extension-supabase project (decision C16). Independent of RLS, native enums, and the complete-contract work (Slice F): it subtracts whatever the packs declare today, and deepens automatically as they declare more. Also carries the plan-expansion docs (Slices F/G, C16, un-defers) from the closed #899, so the plan travels with the work.
How
The match reuses the framework's existing coordinate primitive — nothing new is minted.
elementCoordinates(from@prisma-next/framework-components/ir— the same coordinate walk the contract-space aggregate and cross-space collision check already use) over each pack's contract storage, building a set of declared(namespaceId, entityKind, entityName)coordinates.PostgresDatabaseSchemaNodetree (refactor(postgres): schema-node tree restructure — database→namespace→table→policy diff tree #894's substrate), it omits any node whose coordinate is in that set. A table lives at(schemaName, 'table', tableName); the match is entity-agnostic (enums/roles/policies covered for free as they enter the tree) and coordinate-precise (a pack'sauth.userscannot suppress an app'spublic.users).readonly Contract<SqlStorage>[]) through a widenedinferPslContracthook param — no new type, nothing added tomigrations/types.ts.@relation, and a legitimate same-named relation elsewhere is never stripped).fixtures:checkclean). The framework capability, CLI, introspection scope, anddb verifyare untouched. SQLite doesn't bind the hook; Mongo has no infer.Follow-on
The ownership query has no named home yet. TML-2977 extracts a framework-level
ContractSpaceAggregatebase (pure aggregation of contract spaces + coordinate-precise ownership) that today's migration-state aggregate extends asMigrationSpaceAggregate; this slice's inlineelementCoordinatescall then collapses to a one-line delegation, and re-infer (reconcile the app space via the schema diff) rides the same base. Not gating this slice.Tests
Omission by coordinate + byte-identity; namespace-correctness (
auth-declared name doesn't omit apublictable); entity-kind precision (a same-named non-table entity never suppresses a table — proves the key isn't table-typed); dangling-FK both directions (strip vs keep-a-surviving-same-name); duplicate-name-before-throw; and a real end-to-end test (realpostgresTargetDescriptor+ real family instance).Verification
build · typecheck (143/143) · family-sql + target-postgres suites · fixtures:check byte-identical · lint:deps · lint:casts delta 0 · check:upgrade-coverage — all green locally.
🤖 Generated with Claude Code
Summary by CodeRabbit
contract infernow omits DB tables already covered by stack extension-pack contract spaces.