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

TML-2503: plan complete Supabase contract + extension-aware contract infer - #899

Closed
wmadden-electric wants to merge 1 commit into
mainfrom
extension-supabase-infer-and-completeness
Closed

wmadden-electric wants to merge 1 commit into
mainfrom
extension-supabase-infer-and-completeness

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2503. Planning-doc update for the extension-supabase project. Docs-only.

Summary

Records an 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 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:
    • Slice F — Complete, faithful Supabase contract (all owned auth/storage tables + native enum types + roles, via introspection per C8). Gated on native enums (in flight) — Supabase's auth schema uses native Postgres enum types. It's the ownership source of truth for verify, the db.supabase admin surface, and Slice G.
    • Slice G — Extension-aware contract infer — writes an app-only contract.prisma omitting pack-owned elements. Gated on F + framework/CLI changes.
    • Slice E gate → B–G done.
  • decisions.md — C16: brownfield contract infer must omit extension-owned elements. Records that infer is not extension-aware today (no contract → introspects public, emits everything managed, 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

  • Pure planning docs; no code.
  • The two new slices carry a "shaping needed at pickup" note — the introspection→emit pipeline (F) and how contract infer learns 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.
  • Grounding for C16 (verified against the code): external verify suppresses extra tables/columns/drift and only fails on declaredMissing; the app's own public stays managed (per-contract defaultControlPolicy); contract infer sets 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

  • All commits are signed off (git commit -s).
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated (n/a — doc-only).
  • The PR title is in TML-NNNN: <title> form — Linear-prefixed below.
  • The Skill update section is filled in.

…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]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner July 2, 2026 06:22
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (3)
  • projects/extension-supabase/plan.md is excluded by !projects/**
  • projects/supabase-integration/decisions.md is excluded by !projects/**
  • projects/supabase-integration/deferred.md is excluded by !projects/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 382d9908-00ea-4d92-adee-488142a7e87e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch extension-supabase-infer-and-completeness

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

Copy link
Copy Markdown
Contributor Author

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

paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jul 12, 2026
… 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]>
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.

1 participant