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

TML-2501: declare Supabase roles via a standalone PSL role block - #957

Merged
wmadden merged 1 commit into
mainfrom
tml-2501-supabase-roles-contract
Jul 13, 2026
Merged

wmadden merged 1 commit into
mainfrom
tml-2501-supabase-roles-contract

Conversation

@wmadden-electric

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

Copy link
Copy Markdown
Contributor

PSL gains a standalone role block, and the Supabase pack uses it to declare its three platform roles as first-class contract entities:

namespace unbound {
  role anon {
  }

  role authenticated {
  }

  role service_role {
  }
}

Each lowers to a PostgresRole entity (control: 'external' — roles are referenced, never owned) in the contract's __unbound__ slot: roles are cluster-scoped, and the coordinate is retained unchanged through contract IR and schema IR. db verify against a database missing any declared role fails naming it; against a real or shimmed Supabase database the roles verify clean. The runtime's role vocabulary (SupabaseRoleBinding['role']) derives from the SUPABASE_ROLES tuple instead of hardcoded literal unions, with a type test pinning the public union at exactly 'anon' | 'authenticated' | 'service_role'.

The mechanism

The postgres pack contributes the role keyword through the same PSL-block descriptor surface as native_enum and the policy_* blocks, and the roles are authored inside the explicitly declared unbound namespace — the coordinate for components with no schema binding. Lowering is plain and lexical; no scope machinery exists anywhere. Two rules carry the design:

  • Family: the existing "namespace unbound cannot appear alongside named namespaces" restriction narrows to what it actually protects — late-bound models (whole-contract multi-tenant mode). A blocks-only unbound namespace is legal next to named namespaces, and the unbound / raw __unbound__ spellings resolve to the same id with identical treatment. Top-level extension blocks, previously silently dropped, now lower into the default bucket so a misplaced block errors instead of vanishing.
  • Postgres: a role block declared anywhere other than the unbound namespace is rejected (PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE).

The runtime represents the role vocabulary as a Prisma Next enum handle (enumType('SupabaseRole', …), runtime-only): SupabaseRole.values drives the types, SupabaseRole.members.* replace raw role literals at every selection site, and the JWT claim key is a named constant.

Projection fix that ships with it

The diff-tree projection keys expected namespace nodes by resolved DDL schema, and the unbound sentinel resolves to the default schema (public) for offline comparison. Role entries are root-level diff subjects — they hoist to the database root from every slot and never count toward whether a namespace materializes a schema node. Previously a roles-only unbound slot materialized a spurious empty expected-public node, and if a contract also had a bound public namespace, last-write-wins on the shared key clobbered the real node's tables. Now the unbound slot materializes a node exactly when it has non-role content, so late-binding contracts (where the slot carries the tables) keep today's behavior byte-for-byte. Three pinned cases: roles-only unbound + named namespaces → no public node; single-namespace unbound contract with tables → unchanged; bound public with tables + roles-only unbound → no clobber.

Tests

  • psl-role-authoring.test.ts — the role keyword end-to-end: parse → unbound-slot entity → emit → hydrate.
  • interpreter.extensions.test.ts — generic cluster-scope routing + in-namespace rejection.
  • contract-to-postgres-database-schema-node.test.ts — the three projection cases.
  • contract-roles.test.ts — pins the shipped contract.json role entries to SUPABASE_ROLES, whole-shape.
  • roles-verify.integration.test.ts — the verify vertical: vanilla PGlite fails dbVerify with not-found issues naming each role; a shimmed database passes dbInit + dbVerify clean.
  • supabase-role.types.test-d.ts — the public union pin.

Alternatives considered

  • Injecting the entities via a createNamespace wrapper in the pack's config — a previous revision of this PR did exactly that and was rejected in review: the emitted contract must not carry entities the PSL source doesn't declare, and the namespace factory is a materialization seam, not an authoring surface.
  • Carrying the roles in a named namespace's entries (the auth slot) — works mechanically (the projection hoists role entries from every namespace), but files a cluster-scoped object under a schema-scoped carrier and leaves the coordinate story muddy. The unbound slot is the honest home once the projection handles content-free slots correctly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for authoring Postgres role blocks inside the contract’s unbound namespace.
    • Supabase contracts now include first-class external anon, authenticated, and service_role roles in the shipped unbound namespace.
  • Bug Fixes
    • Supabase JWT role bindings are now normalized and validated against the shipped role definitions, improving consistency.
    • Contract-to-database generation and verification no longer emit unintended namespace schemas when unbound content is role-only.
  • Documentation
    • Updated upgrade guidance for creating Supabase roles locally/within CI via role bootstrapping when needed.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner July 12, 2026 17:58
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Postgres gains top-level cluster-scoped role blocks stored in __unbound__. Supabase declares its standard external roles, shares their type definitions with runtime validation, preserves unbound role slots during projection and serialization, and verifies role presence through integration tests.

Changes

Postgres cluster-scoped role authoring

Layer / File(s) Summary
Route cluster-scoped PSL blocks
packages/1-framework/..., packages/2-sql/2-authoring/contract-psl/*, packages/3-targets/3-targets/postgres/src/core/authoring.ts, packages/2-sql/2-authoring/contract-psl/test/interpreter.extensions.test.ts
Authoring descriptors support entityScope, Postgres recognizes top-level role blocks, and the interpreter lowers cluster-scoped blocks into __unbound__ while rejecting namespace-local declarations.
Project and serialize unbound roles
packages/3-targets/3-targets/postgres/src/core/migrations/*, packages/3-targets/3-targets/postgres/test/*
Role entries are hoisted before namespace materialization, roles-only unbound slots remain distinct, and projection and serialization behavior is tested.
Declare and share Supabase roles
packages/3-extensions/supabase/src/contract/*, packages/3-extensions/supabase/src/runtime/*, packages/3-extensions/supabase/test/contract-roles.test.ts, packages/3-extensions/supabase/test/supabase-role.types.test-d.ts
The Supabase contract declares anon, authenticated, and service_role as external unbound roles; runtime bindings and JWT validation use the shared role vocabulary.
Verify role provisioning
packages/3-extensions/supabase/test/roles-verify.integration.test.ts, skills/extension-author/.../instructions.md
Integration tests cover missing roles and shim-provisioned roles, while upgrade instructions document the new authoring and verification behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Author
  participant PSLInterpreter
  participant PostgresContract
  participant dbVerify
  participant Database
  Author->>PSLInterpreter: declare top-level role
  PSLInterpreter->>PostgresContract: store role in __unbound__
  dbVerify->>PostgresContract: read declared external roles
  dbVerify->>Database: check role existence
  Database-->>dbVerify: return role verification results
Loading

Possibly related PRs

  • prisma/prisma-next#845: Relies on Supabase’s unbound role entities and shared role typing for secondary-root authorization.
  • prisma/prisma-next#950: Adds the Supabase unbound role entities whose presence is verified by this change.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and accurately captures the main change: declaring Supabase roles through a standalone PSL role block.
✨ 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-2501-supabase-roles-contract

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 12, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 155.05 KB (+0.09% 🔺)
postgres / emit 130.06 KB (+0.09% 🔺)
mongo / no-emit 98.64 KB (0%)
mongo / emit 89.41 KB (0%)
cf-worker / no-emit 182.26 KB (+0.08% 🔺)
cf-worker / emit 154.76 KB (+0.08% 🔺)

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/config-loader

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

@prisma-next/emitter

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

@prisma-next/language-server

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 5a2a6ce

@wmadden-electric
wmadden-electric force-pushed the tml-2501-supabase-roles-contract branch from 4827891 to 7d37273 Compare July 13, 2026 07:42
@wmadden-electric wmadden-electric changed the title TML-2501: declare Supabase roles in the pack contract and derive the runtime role vocabulary from them TML-2501: declare Supabase roles via a standalone PSL role block Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: f28e9353-bf31-4a8e-8847-36518710e529

📥 Commits

Reviewing files that changed from the base of the PR and between 92cd08d and 5a2a6ce.

⛔ Files ignored due to path filters (2)
  • projects/extension-supabase/plan.md is excluded by !projects/**
  • projects/supabase-integration/decisions.md is excluded by !projects/**
📒 Files selected for processing (20)
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.diagnostics.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.extensions.test.ts
  • packages/3-extensions/supabase/src/contract/contract.d.ts
  • packages/3-extensions/supabase/src/contract/contract.json
  • packages/3-extensions/supabase/src/contract/contract.prisma
  • packages/3-extensions/supabase/src/contract/roles.ts
  • packages/3-extensions/supabase/src/runtime/supabase-runtime.ts
  • packages/3-extensions/supabase/src/runtime/supabase.ts
  • packages/3-extensions/supabase/test/contract-roles.test.ts
  • packages/3-extensions/supabase/test/roles-verify.integration.test.ts
  • packages/3-extensions/supabase/test/supabase-facade.test.ts
  • packages/3-extensions/supabase/test/supabase-role.types.test-d.ts
  • packages/3-targets/3-targets/postgres/src/core/authoring.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/control-policy.ts
  • packages/3-targets/3-targets/postgres/test/migrations/contract-to-postgres-database-schema-node.test.ts
  • packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts
  • packages/3-targets/3-targets/postgres/test/psl-role-authoring.test.ts
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
💤 Files with no reviewable changes (1)
  • packages/3-extensions/supabase/test/supabase-facade.test.ts
🚧 Files skipped from review as they are similar to previous changes (17)
  • packages/3-extensions/supabase/src/contract/contract.prisma
  • packages/3-extensions/supabase/test/contract-roles.test.ts
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
  • packages/3-targets/3-targets/postgres/src/core/migrations/control-policy.ts
  • packages/3-extensions/supabase/src/contract/contract.json
  • packages/3-targets/3-targets/postgres/test/migrations/contract-to-postgres-database-schema-node.test.ts
  • packages/3-extensions/supabase/src/contract/roles.ts
  • packages/3-extensions/supabase/src/contract/contract.d.ts
  • packages/3-targets/3-targets/postgres/test/psl-role-authoring.test.ts
  • packages/3-extensions/supabase/src/runtime/supabase-runtime.ts
  • packages/3-targets/3-targets/postgres/src/core/authoring.ts
  • packages/3-extensions/supabase/test/roles-verify.integration.test.ts
  • packages/3-extensions/supabase/test/supabase-role.types.test-d.ts
  • packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.ts
  • packages/3-extensions/supabase/src/runtime/supabase.ts
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts

📝 Walkthrough

Walkthrough

Postgres gains unbound-namespace role authoring and projection. Supabase declares its standard external roles, centralizes role typing and JWT validation, and verifies role presence through contract and integration tests.

Changes

Postgres role authoring and routing

Layer / File(s) Summary
Route cluster-scoped PSL blocks
packages/3-targets/3-targets/postgres/src/core/authoring.ts, packages/2-sql/2-authoring/contract-psl/src/interpreter.ts, packages/3-targets/3-targets/postgres/test/*role*, packages/2-sql/2-authoring/contract-psl/test/*
Role blocks lower to UNBOUND_NAMESPACE_ID; invalid placements produce diagnostics, and extension blocks route to the correct namespace bucket.
Project and serialize unbound roles
packages/3-targets/3-targets/postgres/src/core/migrations/*, packages/3-targets/3-targets/postgres/test/migrations/*, packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts
Role entries are hoisted into the database schema while roles-only unbound slots remain distinct from empty public namespaces and survive serialization.

Supabase role contract and runtime

Layer / File(s) Summary
Declare and share Supabase roles
packages/3-extensions/supabase/src/contract/*, packages/3-extensions/supabase/src/runtime/*, packages/3-extensions/supabase/test/contract-roles.test.ts, packages/3-extensions/supabase/test/supabase-role.types.test-d.ts
Supabase declares anon, authenticated, and service_role as external unbound roles and derives runtime role types and JWT validation from the enum contract.

Supabase role verification

Layer / File(s) Summary
Verify role provisioning
packages/3-extensions/supabase/test/roles-verify.integration.test.ts, skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md, packages/3-extensions/supabase/test/supabase-facade.test.ts
Integration tests cover missing roles and shim-created roles; upgrade notes document role declarations and verification behavior, while the facade mock is simplified.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SupabaseContract
  participant PostgresInterpreter
  participant UnboundNamespace
  participant DatabaseVerifier
  SupabaseContract->>PostgresInterpreter: provide role declarations
  PostgresInterpreter->>UnboundNamespace: lower external role entities
  DatabaseVerifier->>UnboundNamespace: compare declared roles with database roles
  UnboundNamespace-->>DatabaseVerifier: return role existence results
Loading

Possibly related PRs

Suggested reviewers: wmadden

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a standalone PSL role block for Supabase roles.
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-2501-supabase-roles-contract

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 force-pushed the tml-2501-supabase-roles-contract branch from 7d37273 to 55257eb Compare July 13, 2026 08:10
@wmadden-electric
wmadden-electric force-pushed the tml-2501-supabase-roles-contract branch from 55257eb to 94870cc Compare July 13, 2026 08:55

@wmadden wmadden 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.

so close, but still such stupid mistakes

@wmadden-electric
wmadden-electric force-pushed the tml-2501-supabase-roles-contract branch 2 times, most recently from de48bfd to 92cd08d Compare July 13, 2026 09:19

@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: 2

🤖 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/2-sql/2-authoring/contract-psl/src/interpreter.ts`:
- Around line 2060-2076: Update mergeNamespaceExtensionEntities to detect
collisions when merging each entriesKey slot, including top-level/namespace
public and unbound spellings. Before assigning the incoming slot values,
identify overlapping entity names in existing[entriesKey] and emit the
established diagnostic, while preserving non-conflicting merges and preventing
the incoming entity from silently replacing the existing declaration.
- Around line 287-294: Update the unbound-namespace validation around
unboundBlock so it checks every namespace matching isUnboundNamespaceBlock, not
only the first result from find(). Detect any model-bearing unbound alias when
hasSibling is true, while preserving the existing allowance for blocks-only
unbound namespaces.
🪄 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: e006424e-a6ce-48c4-a897-dfc4c8275394

📥 Commits

Reviewing files that changed from the base of the PR and between 55257eb and 92cd08d.

⛔ Files ignored due to path filters (2)
  • projects/extension-supabase/plan.md is excluded by !projects/**
  • projects/supabase-integration/decisions.md is excluded by !projects/**
📒 Files selected for processing (20)
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.diagnostics.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.extensions.test.ts
  • packages/3-extensions/supabase/src/contract/contract.d.ts
  • packages/3-extensions/supabase/src/contract/contract.json
  • packages/3-extensions/supabase/src/contract/contract.prisma
  • packages/3-extensions/supabase/src/contract/roles.ts
  • packages/3-extensions/supabase/src/runtime/supabase-runtime.ts
  • packages/3-extensions/supabase/src/runtime/supabase.ts
  • packages/3-extensions/supabase/test/contract-roles.test.ts
  • packages/3-extensions/supabase/test/roles-verify.integration.test.ts
  • packages/3-extensions/supabase/test/supabase-facade.test.ts
  • packages/3-extensions/supabase/test/supabase-role.types.test-d.ts
  • packages/3-targets/3-targets/postgres/src/core/authoring.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/control-policy.ts
  • packages/3-targets/3-targets/postgres/test/migrations/contract-to-postgres-database-schema-node.test.ts
  • packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts
  • packages/3-targets/3-targets/postgres/test/psl-role-authoring.test.ts
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
💤 Files with no reviewable changes (1)
  • packages/3-extensions/supabase/test/supabase-facade.test.ts
🚧 Files skipped from review as they are similar to previous changes (12)
  • packages/3-extensions/supabase/test/supabase-role.types.test-d.ts
  • packages/3-extensions/supabase/test/contract-roles.test.ts
  • packages/3-extensions/supabase/src/contract/contract.json
  • packages/3-extensions/supabase/src/contract/contract.prisma
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
  • packages/3-targets/3-targets/postgres/src/core/authoring.ts
  • packages/3-extensions/supabase/src/runtime/supabase-runtime.ts
  • packages/3-extensions/supabase/src/contract/contract.d.ts
  • packages/3-extensions/supabase/test/roles-verify.integration.test.ts
  • packages/3-targets/3-targets/postgres/test/migrations/contract-to-postgres-database-schema-node.test.ts
  • packages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.ts
  • packages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.ts

PSL gains a role block on the postgres target, authored inside the
explicitly declared unbound namespace:

  namespace unbound {
    role anon {
    }
  }

Each block lowers to a first-class PostgresRole entity
(control: external, namespaceId: __unbound__) through plain lexical
lowering — no scope machinery anywhere. The interpreter narrows the
existing sibling restriction to what it protects: a namespace unbound
block containing MODELS still cannot appear alongside named namespaces
(late binding of tables is a whole-contract mode), while a blocks-only
unbound namespace is legal next to them; both the unbound and raw
__unbound__ spellings resolve to the same id and get identical
treatment. The postgres lowering owns the placement rule: a role block
outside the unbound namespace is rejected
(PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE). Top-level extension
blocks, previously silently dropped, now lower into the default
namespace bucket so a misplaced block errors instead of vanishing.

The diff-tree projection treats role entries as root-level diff
subjects: they hoist to the database root from every slot and never
make a namespace materialize a schema node — a roles-only unbound slot
alongside named namespaces previously produced a spurious empty
expected-public node and could clobber a genuinely bound public
namespace node (last write wins on the ddl-schema key). Late-binding
contracts, where the unbound slot carries the tables, keep todays
behavior.

The runtime represents the role vocabulary as a Prisma Next enum
handle (enumType SupabaseRole): SupabaseRoleBinding.role derives from
SupabaseRole.values, role selections use the typed member accessors
instead of string literals, the JWT claim key is a named constant, and
a type test pins the public union unchanged. db verify against a
database missing the roles fails naming each of them; a shimmed
database verifies clean.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric force-pushed the tml-2501-supabase-roles-contract branch from 92cd08d to 5a2a6ce Compare July 13, 2026 11:14
@wmadden-electric
wmadden-electric added this pull request to the merge queue Jul 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 13, 2026
@wmadden
wmadden added this pull request to the merge queue Jul 13, 2026
Merged via the queue into main with commit 05467c0 Jul 13, 2026
20 checks passed
@wmadden
wmadden deleted the tml-2501-supabase-roles-contract branch July 13, 2026 13:49
wmadden-electric added a commit that referenced this pull request Jul 15, 2026
Integrates origin/main (which merged #957 PSL role blocks + the
native-enum and dependency PRs) into the slice. Conflicts resolved
preserving both intents:

- supabase roles.ts: keep #957 SupabaseRole enumType (+ JWT claim key
  + isSupabaseRole, the runtime vocabulary source of truth) AND our
  anon/authenticated role() reference handles; the handles reference
  the same anon/authenticated identities SupabaseRole declares.
- supabase contract-roles.test.ts (add/add): merge #957 contract-shape
  test (__unbound__ role slot == SupabaseRole.values) with our
  anon/authenticated handle-shape test.
- interpreter.ts: reconcile #957 refactor (lowerExtensionBlocksForName
  space takes a blocks map; top-level extension blocks pass) with our
  resolved-model-refs threading (composedPslBlockDescriptors +
  per-namespace table resolver), threaded through both call sites.
- postgres authoring.ts auto-merged: #957 role block (lowerRoleFrom
  Block, outside-unbound rejection) coexists with our policy_* and the
  entity-handle hook.
- upgrade instructions: keep all three per-PR notes as separate blocks.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden-electric added a commit that referenced this pull request Jul 15, 2026
…ocks

The postgres entity-handle hook lowered a TS role() under the model
default namespace (public); roles are cluster-scoped, so they belong
in __unbound__ — matching #957 PSL role blocks (lowerRoleFromBlock)
and the PostgresRole class contract. Flip both the new PostgresRole
namespaceId and the rows.push namespaceId in postgresLowerEntityHandles
to UNBOUND_NAMESPACE_ID.

Verify keys roles by name at the root, so a missing declared role
still fails verify (walking skeleton green) — only the emitted slot
moves. Parity strengthened: a role is now authored in BOTH surfaces
(TS role(app_role) in entities vs PSL namespace unbound { role app_role
{} }) and asserted to lower to an identical PostgresRole under
__unbound__.entries.role — the inline whole-contract toEqual and the
emit-parity fixture both cover it byte-identically.

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