Context
#550 completed the Prisma/Hyperdrive pilot and production activation for the first pure-owner families. This follow-up tracks the remaining business tables without treating policy count as the goal.
Already enforced in production with ENABLE + FORCE ROW LEVEL SECURITY:
Todo
DashboardLinkClick
DashboardLinkPin
BusUserPreference
The runtime pattern is a short interactive Prisma transaction, transaction-local set_config('app.user_id', ..., true), and all protected queries on the exact transaction client. CI uses a dedicated LOGIN NOINHERIT NOBYPASSRLS role.
Remaining access families
- Uploads: owner-only pending/write paths, but published/referenced uploads need narrowly defined public reads. Do not apply a blanket owner SELECT policy.
- Homework completion: owner writes coexist with public profile contribution aggregates. Move the public aggregate to a narrow view/function or remove it before owner-only SELECT.
- Collaborative content: define anonymous, authenticated, soft-banned, moderator, and admin matrices before policies.
- Better Auth tables: use a separate auth-service database identity because many queries happen before an end-user identity exists.
- Catalog/importer tables: enforce role grants for read-only runtime/importer ownership; avoid meaningless
USING (true) policies.
Hyperdrive / operations
- Provision a least-privilege production runtime role with
NOBYPASSRLS; application owner/migration credentials remain separate.
- Bind auth-sensitive traffic to a cache-disabled Hyperdrive configuration. Hyperdrive currently caches only queries whose functions are immutable, so
current_setting policy reads should not be cacheable, but the explicit binding avoids relying on that implementation detail.
- Never use session-scoped
SET with transaction pooling; identity must be transaction-local.
Acceptance criteria
References: #550, #596, #598, #599, #600.
Context
#550 completed the Prisma/Hyperdrive pilot and production activation for the first pure-owner families. This follow-up tracks the remaining business tables without treating policy count as the goal.
Already enforced in production with
ENABLE+FORCE ROW LEVEL SECURITY:TodoDashboardLinkClickDashboardLinkPinBusUserPreferenceThe runtime pattern is a short interactive Prisma transaction, transaction-local
set_config('app.user_id', ..., true), and all protected queries on the exact transaction client. CI uses a dedicatedLOGIN NOINHERIT NOBYPASSRLSrole.Remaining access families
USING (true)policies.Hyperdrive / operations
NOBYPASSRLS; application owner/migration credentials remain separate.current_settingpolicy reads should not be cacheable, but the explicit binding avoids relying on that implementation detail.SETwith transaction pooling; identity must be transaction-local.Acceptance criteria
USINGandWITH CHECKwhere applicable.References: #550, #596, #598, #599, #600.