Raw queries against the cell_grant table.
Resource-side ACL for cells: each row admits a principal at a level
(viewer | editor). Principal is discriminated by which columns are
set — actor_id (single actor) xor (role, scope_id?) (any holder
of a matching role_grant). Owner is implicit on cell.created_by and never
appears in this table.
Convention: deps: QueryDeps first, no audit side effects, mutations
return the affected row (or null for not-found).
query_cell_grant_create upserts on the relevant partial unique index so
re-granting the same principal updates level rather than producing
duplicate rows. The two principal shapes use different indexes:
- Actor-shaped:
idx_cell_grant_unique_actor on (cell_id, actor_id). - Role-shaped:
idx_cell_grant_unique_role_scope on (cell_id, role, scope_id)
with NULLS NOT DISTINCT so two (role, NULL) grants on the same cell
collide.