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

TML-2503: reconcile extension-supabase spec/plan to as-built (slice A) - #839

Merged
wmadden merged 1 commit into
mainfrom
tml-2503-extension-supabase
Jun 16, 2026
Merged

wmadden merged 1 commit into
mainfrom
tml-2503-extension-supabase

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2503. First slice of the final integration project — a docs-only reconciliation. The runtime half shipped early under runtime-target-layer (ADR 230), so the spec/plan had drifted from reality.

At a glance

The spec now opens with an as-built/remaining-scope section instead of describing a runtime that no longer matches the code:

The following is complete and green on `main`:
- Package scaffold: real /pack, /contract, /runtime
- Runtime: SupabaseRuntimeImpl (session-coupled connections), async supabase<TContract>(),
  asUser/asAnon/asServiceRole, JWT validation — shipped under ADR 230
- /contract model handles: AuthUser/AuthIdentity/StorageBucket/StorageObject (no roles/RoleRef export)
- examples/supabase: real, green; external migrate/verify, FK cascade, RLS enforcement
  (caveat: RLS is raw-SQL fixture, roles hardcoded — that's the remaining work)

Decision

Docs-only. Reconcile the extension-supabase artifacts to as-built reality and re-plan the remaining work:

  1. spec.md — fix the runtime surface (single-param supabase<TContract>, async asUser, session-coupled connections — not SET LOCAL/withRawConnection/execute()-override); /contract ships model handles only (no roles/RoleRef); corrected FRs/ACs; supabase:auth.AuthUser.
  2. plan.md — scaffold + runtime slices marked done; remaining slices A–E with explicit gates (postgres-rls verticals, namespace close-out).
  3. decisions.md C5 — settle the /contract design: keep extensionModel-branded model handles, drop the roles/RoleRef hand-export (roles resolve via PSL roles=[…] aggregate + postgres-rls's PostgresRole IR).

How it was produced

Drive process: sonnet-mid implementer authored the reconciliation from a verified ground-truth brief; opus-high review pass returned APPROVE-WITH-NITS; nits applied (handle name auth.User→auth.AuthUser, a forward-reference noting the PSL policy grammar is postgres-rls's call to pin, and slice-terminology consistency).

Reviewer notes

  • Pure docs; no code touched (git diff --name-only = the 3 files).
  • The At-a-glance PSL sample still shows the single-block policy { operation = … } form on purpose — postgres-rls's own spec hasn't yet pinned single-block vs. per-operation policy_select keywords, so a forward-reference note flags it rather than this spec unilaterally inventing the grammar. Slice B settles it.
  • Remaining slices B (RLS via framework surface) and C (roles first-class) gate on postgres-rls (TML-2868: SELECT RLS policies, dependable end-to-end — authored in PSL, enforced, drift fails verify #771 + later verticals); D (explicit auth.users query) is functionally unblocked (namespace surface merged) but formally gated on explicit-namespace-dsl close-out; E is docs + real-Supabase acceptance.

Testing performed

n/a — documentation only.

Skill update

n/a — internal planning docs only; 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 Linear-prefixed.
  • The Skill update section is filled in (n/a — internal only).

…(ADR 230)

The runtime half shipped under runtime-target-layer (ADR 230), so the
spec/plan were stale. Reconcile them to reality and lay out the remaining
slices.

- spec.md: add an "As-built & remaining scope" section; fix the runtime
  surface (single-param supabase<TContract>, async asUser, session-coupled
  connections — not SET LOCAL/withRawConnection); /contract ships model
  handles only (no roles/RoleRef export); fix FRs/ACs; supabase:auth.AuthUser
- plan.md: mark scaffold + runtime slices done; re-plan remaining slices
  A–E with explicit gates (postgres-rls verticals, namespace close-out)
- decisions.md C5: settle the /contract design — keep model handles, drop
  the roles/RoleRef hand-export (roles via PSL aggregate + PostgresRole IR)

Reviewed (opus): APPROVE-WITH-NITS; nits applied (handle name, PSL-grammar
forward-reference, slice terminology).

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 June 16, 2026 12:26
@coderabbitai

coderabbitai Bot commented Jun 16, 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/extension-supabase/spec.md is excluded by !projects/**
  • projects/supabase-integration/decisions.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: 7b8390f0-9b88-43c0-a138-69a5b11eba4f

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 tml-2503-extension-supabase

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 and usage tips.

@wmadden
wmadden added this pull request to the merge queue Jun 16, 2026
Merged via the queue into main with commit a3da203 Jun 16, 2026
19 checks passed
@wmadden
wmadden deleted the tml-2503-extension-supabase branch June 16, 2026 13:41
wmadden-electric added a commit that referenced this pull request Jun 18, 2026
Main shipped the 0.14.0 publish bump (#843) and several follow-ups
(TML-2916 #838, TML-2503 #839, TML-2787 #683, TML-2893 #849, ci-fix
#847) while slice 1 was in review. Merge to pick them up.

Resolution:
- `skills/extension-author/.../0.13-to-0.14/instructions.md` — union of
  the slice's TML-2919 entry and main's TML-2916 entry as two distinct
  HTML-comment blocks, matching the file's per-ticket convention.
  Per the skill spec's rebase scenario (lines 122-130): existing entries
  in the just-shipped 0.13-to-0.14 directory may stay in place; we do
  not relocate the TML-2919 entry to 0.14-to-0.15.
- Lockfile + example fixtures + apps + all other non-slice files —
  take main's side cleanly (the branch hadn't touched them; auto-merge
  resolved to main's content). `pnpm install` confirms the lockfile is
  consistent.
- No `src/` conflicts — only the one instructions.md conflict above.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jul 12, 2026
…ot (slice D) (prisma#845)

## Linked issue

Refs [TML-2503](https://linear.app/prisma-company/issue/TML-2503). Slice
D of extension-supabase (slice A merged in prisma#839). Slice contract:
`projects/extension-supabase/slices/d-service-role-internal-namespaces/spec.md`;
design in decision **C15**.

## At a glance

```ts
const admin = db.asServiceRole();
admin.sql.public.profile…                   // primary root (app contract) — unchanged
admin.supabase.sql.auth.users.select({ … }) // secondary root (extension contract)
admin.supabase.orm.auth.AuthUser.find({ … })

db.asAnon().supabase                         // ✗ not on the type — service_role only
```

## Decision

Admin access to Supabase-internal tables (`auth.*`, `storage.*`) is
exposed as a **separate secondary root** `db.asServiceRole().supabase` —
**not** by merging the extension contract into the app contract (a first
attempt did that; rejected in review). The `.supabase` facet is the
extension contract's **own intact** `ExecutionContext` + a second
`SupabaseRuntimeImpl` bound to it, **sharing the app runtime's
driver/pool + the `service_role` session**, with marker-verification off
(the `external` extension contract owns no app-space marker).
`asServiceRole().sql`/`.orm` stay app-contract-only; `asUser`/`asAnon`
are unchanged (no `.supabase`).

## Why a separate root, not a merge

The runtime is **contract-bound by `storageHash`**:
`SqlFamilyAdapter.validatePlan` asserts `plan.meta.storageHash ===
context.contract.storage.storageHash`. A plan built against the
extension contract carries the extension's hash and can't run on the app
runtime — so the two roots are genuinely separate (own context + own
runtime), sharing only the driver/pool. Merging two `Contract`s also
breaks codec-registry uniqueness and the marker check. Two intact
contexts/runtimes sharing one pool is the ADR 230 pattern.

## Behavior changes & evidence

- `db.asServiceRole().supabase.{sql,orm}` query the extension contract;
`asServiceRole().sql`/`.orm` are app-only; `asUser`/`asAnon` have no
`.supabase`. Impl:
`packages/3-extensions/supabase/src/runtime/supabase.ts`
(`SupabaseInternalDb`, `ServiceRoleDb`, `buildExtensionContract`,
`extContext`/`extRuntime`). Evidence:
`examples/supabase/test/explicit-namespace-query.integration.test.ts`
(reads `auth.users` via `.supabase.sql` **and** `.orm`; SQL targets
`"auth"."users"`; `current_setting('role') = 'service_role'`) +
`service-role-namespaces.test-d.ts` (type-level: secondary root carries
`auth`/`storage`; primary root + `asAnon`/`asUser` do not).

## Reviewer notes

- **Independent opus review: APPROVE-WITH-NITS** — confirmed one shared
pool (no double-close), `service_role` binding intact on the ext path,
marker-verify correctly scoped (ext off, app on), no `auth.*` leak to
anon/user, per-contract `validatePlan`. The one acted nit (doc comment
explaining `SupabaseInternalDb` omits `transaction`) is applied.
- This single commit **replaces an earlier merge approach**
(force-pushed away) — the diff is the net secondary-root design.
- `ext-contract-type.ts` is a no-`as` type alias naming the extension
`Contract` distinctly from the framework `Contract` (keeps `lint:casts`
delta 0).
- **v1 limitation (documented):** no single `transaction` spanning the
app root and `.supabase` (separate runtimes, unpinned connections). The
principled fix — a `Runtime` bound to the **aggregate contract** — is
recorded as future direction in C15 + `deferred.md`.

## Testing performed

`pnpm exec turbo run typecheck test lint --filter
@prisma-next/example-supabase --filter @prisma-next/extension-supabase`
— green (example suite 9 tests, incl. the `.supabase` sql+orm reads).
`pnpm lint:casts` delta 0; `pnpm lint:deps` clean. CI re-running on
push.

## Skill update

n/a — the only user-facing surface change (the
`asServiceRole().supabase` admin root) is documented in decision C15 +
`overview.md`; no CLI/config/error-code change.

## Checklist

- [x] All commits are signed off (`git commit -s`).
- [x] I read CONTRIBUTING.md and the change is scoped to one logical
concern.
- [x] Tests are updated (integration + type-level).
- [x] PR title is Linear-prefixed.
- [x] **Skill update** filled in.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added an additive `db.asServiceRole().supabase` admin root that
enables service-role access to Supabase internal namespaces (e.g.,
`auth`, `storage`) via `.sql` and `.orm`, while keeping the primary
`asServiceRole()` surface restricted to `public`.
* **Tests**
* Added integration coverage for internal-namespace reads, emitted SQL
targeting, and role-scoped execution for both app and internal surfaces.
* Added compile-time typing checks for `service_role`, `anon`, and
user/JWT namespace visibility.
* **Documentation**
* Updated upgrade instructions to describe the new secondary `.supabase`
surface and related exported types.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: willbot <[email protected]>
Co-authored-by: Claude Opus 4.8 <[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