Repository navigation
TML-2503: plan complete Supabase contract + extension-aware contract infer - #899
wmadden-electric wants to merge 1 commit into
Conversation
…Supabase) Operator scope decision: `contract infer` in a Supabase environment must write a meaningful contract.prisma that omits every element the Supabase extension owns. That makes brownfield adoption a launch requirement and requires the extension to ship a complete/faithful contract (the ownership source of truth). - plan.md: mark Slice D done (#845); add Slice F (complete Supabase contract via introspection — gated on native enums) and Slice G (extension-aware contract infer — subtracts pack-owned elements; gated on F + CLI work); Slice E gate -> B-G. - decisions.md: C16 (brownfield infer omits extension-owned elements; infer is not extension-aware today; ownership from the pack complete contract). - deferred.md: un-defer introspection-emit + adopt-from-database (now Slices F/G). Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: willbot <[email protected]>
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (3)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Closing: folding these plan/decision docs into the Slice G work branch (TML-2962) so the plan updates alongside the work as it exposes new information. The Slice G section also needed correcting — G is no longer gated on Slice F (the omission mechanism subtracts whatever the pack's contract space declares today; F only deepens what gets omitted), and the ownership mechanism has since been shaped (aggregate-in via the target inferPslContract hook). |
… describe (prisma#919) ## 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 prisma#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 (prisma#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](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Linked issue
Refs TML-2503. Planning-doc update for the extension-supabase project. Docs-only.
Summary
Records an operator scope decision:
contract inferin a Supabase environment must write a meaningfulcontract.prismathat omits every element the Supabase extension owns. That makes brownfield adoption a launch requirement — and requires the extension to ship a complete, faithful contract as the source of truth for what it owns.What changed
plan.md— mark Slice D done (TML-2503: Supabase-internal namespaces via a secondary db.supabase root (slice D) #845); add:auth/storagetables + native enum types + roles, via introspection per C8). Gated on native enums (in flight) — Supabase'sauthschema uses native Postgres enum types. It's the ownership source of truth for verify, thedb.supabaseadmin surface, and Slice G.contract infer— writes an app-onlycontract.prismaomitting pack-owned elements. Gated on F + framework/CLI changes.decisions.md— C16: brownfieldcontract infermust omit extension-owned elements. Records that infer is not extension-aware today (no contract → introspectspublic, emits everythingmanaged, blind to pack ownership), and that making it extension-aware (subtract the stack packs' owned set) is a launch requirement, not a follow-up.deferred.md— un-defer "introspection-based emit" and "adopt --from-database" (now Slices F/G).Reviewer notes
contract inferlearns the pack's owned set + the subtraction rule (G) are non-trivial framework/CLI design still to be shaped; this PR represents the deliverables + gates, not the mechanism.externalverify suppresses extra tables/columns/drift and only fails ondeclaredMissing; the app's ownpublicstaysmanaged(per-contractdefaultControlPolicy);contract infersets no control policy and consults no extension pack.Testing performed
n/a — documentation only.
Skill update
n/a — internal planning docs; no user-facing surface change.
Checklist
git commit -s).TML-NNNN: <title>form — Linear-prefixed below.