Repository navigation
TML-2501: declare Supabase roles via a standalone PSL role block - #957
Conversation
📝 WalkthroughWalkthroughPostgres gains top-level cluster-scoped ChangesPostgres cluster-scoped role authoring
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
size-limit report 📦
|
d3282b9 to
4827891
Compare
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/config-loader
@prisma-next/emitter
@prisma-next/language-server
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
4827891 to
7d37273
Compare
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (20)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (17)
📝 WalkthroughWalkthroughPostgres 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. ChangesPostgres role authoring and routing
Supabase role contract and runtime
Supabase role verification
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
7d37273 to
55257eb
Compare
55257eb to
94870cc
Compare
wmadden
left a comment
There was a problem hiding this comment.
so close, but still such stupid mistakes
de48bfd to
92cd08d
Compare
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (2)
projects/extension-supabase/plan.mdis excluded by!projects/**projects/supabase-integration/decisions.mdis excluded by!projects/**
📒 Files selected for processing (20)
packages/2-sql/2-authoring/contract-psl/src/interpreter.tspackages/2-sql/2-authoring/contract-psl/test/interpreter.diagnostics.test.tspackages/2-sql/2-authoring/contract-psl/test/interpreter.extensions.test.tspackages/3-extensions/supabase/src/contract/contract.d.tspackages/3-extensions/supabase/src/contract/contract.jsonpackages/3-extensions/supabase/src/contract/contract.prismapackages/3-extensions/supabase/src/contract/roles.tspackages/3-extensions/supabase/src/runtime/supabase-runtime.tspackages/3-extensions/supabase/src/runtime/supabase.tspackages/3-extensions/supabase/test/contract-roles.test.tspackages/3-extensions/supabase/test/roles-verify.integration.test.tspackages/3-extensions/supabase/test/supabase-facade.test.tspackages/3-extensions/supabase/test/supabase-role.types.test-d.tspackages/3-targets/3-targets/postgres/src/core/authoring.tspackages/3-targets/3-targets/postgres/src/core/migrations/contract-to-postgres-database-schema-node.tspackages/3-targets/3-targets/postgres/src/core/migrations/control-policy.tspackages/3-targets/3-targets/postgres/test/migrations/contract-to-postgres-database-schema-node.test.tspackages/3-targets/3-targets/postgres/test/postgres-contract-serializer.test.tspackages/3-targets/3-targets/postgres/test/psl-role-authoring.test.tsskills/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]>
92cd08d to
5a2a6ce
Compare
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]>
…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]>
PSL gains a standalone
roleblock, and the Supabase pack uses it to declare its three platform roles as first-class contract entities:Each lowers to a
PostgresRoleentity (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 verifyagainst 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 theSUPABASE_ROLEStuple 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
rolekeyword through the same PSL-block descriptor surface asnative_enumand thepolicy_*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:namespace unboundcannot 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 theunbound/ 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.roleblock 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.valuesdrives 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-publicnode, and if a contract also had a boundpublicnamespace, 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 → nopublicnode; single-namespace unbound contract with tables → unchanged; boundpublicwith tables + roles-only unbound → no clobber.Tests
psl-role-authoring.test.ts— therolekeyword 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 shippedcontract.jsonrole entries toSUPABASE_ROLES, whole-shape.roles-verify.integration.test.ts— the verify vertical: vanilla PGlite failsdbVerifywithnot-foundissues naming each role; a shimmed database passesdbInit+dbVerifyclean.supabase-role.types.test-d.ts— the public union pin.Alternatives considered
createNamespacewrapper 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.authslot) — 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
roleblocks inside the contract’s unbound namespace.anon,authenticated, andservice_roleroles in the shipped unbound namespace.