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

TML-2962: contract infer omits elements the stack's extension packs describe - #919

Merged
wmadden-electric merged 9 commits into
mainfrom
tml-2962-infer-omits-aggregate-elements
Jul 7, 2026
Merged

wmadden-electric merged 9 commits into
mainfrom
tml-2962-infer-omits-aggregate-elements

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

What

contract infer now writes a contract.prisma containing 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.

  • The Postgres inferrer runs 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.
  • While gathering the PostgresDatabaseSchemaNode tree (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's auth.users cannot suppress an app's public.users).
  • The family instance forwards the packs' already-assembled contracts (readonly Contract<SqlStorage>[]) through a widened inferPslContract hook param — no new type, nothing added to migrations/types.ts.
  • Omission happens before the cross-schema duplicate-name check and relation inference; surviving tables' foreign keys are dropped only when the referenced name was omitted and has no surviving table (so no dangling @relation, and a legitimate same-named relation elsewhere is never stripped).
  • Empty/absent input → byte-identical output (fixtures:check clean). The framework capability, CLI, introspection scope, and db verify are 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 ContractSpaceAggregate base (pure aggregation of contract spaces + coordinate-precise ownership) that today's migration-state aggregate extends as MigrationSpaceAggregate; this slice's inline elementCoordinates call 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 a public table); 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 (real postgresTargetDescriptor + 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

  • New Features
    • contract infer now omits DB tables already covered by stack extension-pack contract spaces.
    • Cross-space foreign keys are now qualified with the owning pack’s namespace and contract-space identifiers for clearer relation fields and printed PSL.
  • Bug Fixes
    • Omission is scoped to the exact coordinate (avoiding suppression across different namespaces/same-named entities).
    • Filters only dangling foreign keys that target omitted tables while preserving valid relationships.
  • Tests
    • Added unit and integration coverage for described-contract omission, cross-space FK inference, and malformed-pack error handling.
  • Documentation
    • Updated upgrade guidance to reflect the new omission/qualification behavior.

wmadden-electric and others added 3 commits July 6, 2026 17:14
…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]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner July 7, 2026 07:06
@coderabbitai

coderabbitai Bot commented Jul 7, 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: 12189a20-42fb-45df-9036-9b01d4a4f78a

📥 Commits

Reviewing files that changed from the base of the PR and between b2031c8 and 36a8fd2.

📒 Files selected for processing (1)
  • packages/1-framework/1-core/framework-components/src/ir/storage.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/1-framework/1-core/framework-components/src/ir/storage.ts

📝 Walkthrough

Walkthrough

The 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.

Changes

Extension-aware contract inference

Layer / File(s) Summary
Coordinate keys and integrity
packages/1-framework/1-core/framework-components/src/ir/storage.ts, packages/1-framework/1-core/framework-components/src/exports/ir.ts, packages/1-framework/1-core/framework-components/test/element-coordinates.test.ts, packages/1-framework/3-tooling/migration/src/aggregate/check-integrity.ts
Adds coordinateKey, re-exports it, tests it, and switches integrity disjointness tracking to use the shared key.
SQL hook threading
packages/2-sql/9-family/src/core/control-target-descriptor.ts, packages/2-sql/9-family/src/core/migrations/types.ts, packages/2-sql/9-family/src/core/control-instance.ts, packages/2-sql/9-family/src/exports/control.ts, packages/2-sql/9-family/src/exports/psl-infer.ts, packages/2-sql/9-family/src/core/psl-contract-infer/relation-inference.ts
Introduces described-contract types, widens the inferPslContract hook shape, threads extension contract spaces through the SQL family instance, and re-exports the relation helper used by the target implementation.
Postgres inference and exports
packages/3-targets/3-targets/postgres/src/core/psl-infer/infer-psl-contract.ts, packages/3-targets/3-targets/postgres/src/exports/control.ts, packages/2-sql/9-family/src/core/psl-contract-infer/printer-config.ts, packages/3-extensions/supabase/package.json
Updates Postgres PSL inference to consume described contracts, omit owned tables, rewrite relation fields with namespace/contract qualifiers, and forward the new parameter from the Postgres target descriptor.
Inference tests and guidance
packages/2-sql/9-family/test/psl-infer-described-contracts.test.ts, packages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract-described-contracts.test.ts, packages/3-extensions/supabase/test/infer-cross-space-fk.integration.test.ts, skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
Adds unit and integration coverage for described-contract omission and cross-space relation printing, and documents the contract-infer behavior change for extension authors.

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
Loading

Possibly related PRs

  • prisma/prisma-next#745: Both PRs modify createSqlFamilyInstance in packages/2-sql/9-family/src/core/control-instance.ts and work in the same family-instance flow.
  • prisma/prisma-next#752: Both PRs build on cross-space foreign-key and relation qualifier plumbing.

Suggested reviewers: wmadden, aqrln

🚥 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 clearly summarizes the main change: contract inference now omits elements already described by extension packs.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2962-infer-omits-aggregate-elements

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.

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 148.99 KB (+0.01% 🔺)
postgres / emit 126.45 KB (0%)
mongo / no-emit 98.2 KB (-0.01% 🔽)
mongo / emit 89.39 KB (0%)
cf-worker / no-emit 175.55 KB (+0.02% 🔺)
cf-worker / emit 150.97 KB (0%)

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/config-loader

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

@prisma-next/emitter

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

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@919

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 36a8fd2

wmadden-electric and others added 2 commits July 7, 2026 10:44
…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]>
@wmadden-electric wmadden-electric changed the title TML-2962: contract infer omits elements the aggregate contract describes TML-2962: contract infer omits elements the stack's extension packs describe Jul 7, 2026

@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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 720677e and fe2610e.

⛔ Files ignored due to path filters (4)
  • projects/extension-supabase/plan.md is excluded by !projects/**
  • projects/extension-supabase/slices/g-extension-aware-infer/spec.md is excluded by !projects/**
  • projects/supabase-integration/decisions.md is excluded by !projects/**
  • projects/supabase-integration/deferred.md is excluded by !projects/**
📒 Files selected for processing (6)
  • packages/2-sql/9-family/src/core/control-instance.ts
  • packages/2-sql/9-family/src/core/migrations/types.ts
  • packages/2-sql/9-family/test/psl-infer-described-contracts.test.ts
  • packages/3-targets/3-targets/postgres/src/core/psl-infer/infer-psl-contract.ts
  • packages/3-targets/3-targets/postgres/src/exports/control.ts
  • packages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract-described-contracts.test.ts

Comment on lines +502 to +507
readonly inferPslContract?: (schema: SqlSchemaIRNode) => PslDocumentAst;
readonly inferPslContract?: (
schema: SqlSchemaIRNode,
describedContracts?: readonly Contract<SqlStorage>[],
) => PslDocumentAst;

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.

Extract whatever interface this is attached to into a separate file, not types.ts

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.

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.

Comment on lines +538 to +543
{
readonly inferPslContract?: (
schema: SqlSchemaIRNode,
describedContracts?: readonly Contract<SqlStorage>[],
) => PslDocumentAst;
},

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.

Use a real interface, not this nonsense inline type def

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.

Done in 323b56c1a. The anonymous inline structural type is gone — the hook is now read via a cast to the named SqlControlTargetDescriptor.

Comment on lines +81 to +90
/**
* 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}`;
}

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.

This function already exists in other places. Can we use a consistent implementation?

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.

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.

wmadden-electric and others added 3 commits July 7, 2026 14:44
… (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]>
@wmadden-electric
wmadden-electric requested a review from wmadden July 7, 2026 13:59
export function coordinateKey(
coordinate: Pick<EntityCoordinate, 'namespaceId' | 'entityKind' | 'entityName'>,
): string {
return JSON.stringify([coordinate.namespaceId, coordinate.entityKind, coordinate.entityName]);

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.

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('-')?

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.

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]>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 12189a20-42fb-45df-9036-9b01d4a4f78a

📥 Commits

Reviewing files that changed from the base of the PR and between b2031c8 and 36a8fd2.

📒 Files selected for processing (1)
  • packages/1-framework/1-core/framework-components/src/ir/storage.ts
 _______________________________________________
< Caches are bugs waiting to happen. - Rob Pike >
 -----------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
📝 Walkthrough

Walkthrough

The 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.

Changes

Extension-aware contract inference

Layer / File(s) Summary
Coordinate keys and integrity
packages/1-framework/1-core/framework-components/src/ir/storage.ts, packages/1-framework/1-core/framework-components/src/exports/ir.ts, packages/1-framework/1-core/framework-components/test/element-coordinates.test.ts, packages/1-framework/3-tooling/migration/src/aggregate/check-integrity.ts
Adds coordinateKey, re-exports it, tests its behavior, and switches integrity disjointness tracking to use the shared key.
SQL hook threading
packages/2-sql/9-family/src/core/control-target-descriptor.ts, packages/2-sql/9-family/src/core/migrations/types.ts, packages/2-sql/9-family/src/core/control-instance.ts, packages/2-sql/9-family/src/exports/control.ts, packages/2-sql/9-family/src/exports/psl-infer.ts, packages/2-sql/9-family/src/core/psl-contract-infer/relation-inference.ts
Introduces described-contract types, widens the inferPslContract hook shape, threads extension contract spaces through the SQL family instance, and re-exports the relation helper used by the target implementation.
Postgres inference and exports
packages/3-targets/3-targets/postgres/src/core/psl-infer/infer-psl-contract.ts, packages/3-targets/3-targets/postgres/src/exports/control.ts, packages/2-sql/9-family/src/core/psl-contract-infer/printer-config.ts, packages/3-extensions/supabase/package.json
Updates Postgres PSL inference to consume described contracts, omit owned tables, rewrite relation fields with namespace/contract qualifiers, and forward the new parameter from the Postgres target descriptor.
Inference tests and guidance
packages/2-sql/9-family/test/psl-infer-described-contracts.test.ts, packages/3-targets/3-targets/postgres/test/psl-infer/infer-psl-contract-described-contracts.test.ts, packages/3-extensions/supabase/test/infer-cross-space-fk.integration.test.ts, skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
Adds unit and integration coverage for described-contract omission and cross-space relation printing, and documents the contract-infer behavior change for extension authors.

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
Loading

Possibly related PRs

  • prisma/prisma-next#745: Both PRs modify createSqlFamilyInstance in packages/2-sql/9-family/src/core/control-instance.ts and work in the same family-instance flow.
  • prisma/prisma-next#894: Both PRs touch inferPostgresPslContract and its surrounding Postgres PSL inference plumbing.

Suggested reviewers: wmadden

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds runtime code changes, but #899 is docs-only planning work and the expected plan/decision/deferred doc edits are not shown here. Keep this PR to the planning-doc updates from #899, or split the implementation into a separate PR.
Out of Scope Changes check ⚠️ Warning The PR adds extensive runtime and test code across SQL/framework/postgres packages, which is far beyond the docs-only planning update in #899. Move the runtime and test changes into a separate implementation PR and leave this branch limited to the requested docs update.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main behavior change: extension-pack-described elements are omitted during contract infer.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2962-infer-omits-aggregate-elements

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.

@wmadden-electric
wmadden-electric added this pull request to the merge queue Jul 7, 2026
Merged via the queue into main with commit 23a9576 Jul 7, 2026
28 of 29 checks passed
@wmadden-electric
wmadden-electric deleted the tml-2962-infer-omits-aggregate-elements branch July 7, 2026 16:12
wmadden-electric added a commit that referenced this pull request Jul 8, 2026
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]>
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