Appearance
0003: Drizzle and row-level security
Context
The old repo enforced tenant isolation by convention and needed 143 fixes after two critical cross-tenant vulnerabilities.
Decision
Every table except principal carries entity_id under a Postgres row-level security policy. The app connects as a non-owner role. The entity is resolved from the authenticated session only. Drizzle with plain SQL migrations. Migrations are additive only.
Consequences
A cross-entity test runs in every pipeline from slice 1. The director's personal data is a third entity.
Amendment, 2026-11-03: principal under row-level security (#297)
principal still carries no entity_id, but it is now under row-level security too (migration 0031; policies in src/platform/policies.sql). The app role reads only the person in context and the people named in the activity log of a company that person has access to, adds only the row in context when someone signs up, and deletes only its own row. Signing in finds a person by email, before anyone is in context, through the security definer function principal_id_for_email (migration 0027).