Also available: Markdown version · llms.txt · full site content
Database
Row-level security
Set a user column when you create a table and CubiBase writes the PostgreSQL policy for you: a row belongs to the user whose id it carries.
The model
Every table created through CubiBase has Row Level Security enabled and forced. Two policies exist from the start, and the Policies screen lets you add, edit, or drop your own:
| Policy | Role | Effect |
|---|---|---|
| Developer policy | sql (Console) | Full access, so you can manage every row |
| Isolation policy | api (Data API) | Only rows where the user column equals the caller’s id |
The user column must be a text column on the new table — owner_id in these docs. Its value is compared to the verified JWT subject, which the engine sets as cubibase.user_id for the transaction.
The policy CubiBase creates
For a table customers with user column owner_id, the isolation policy is equivalent to:
CREATE POLICY customers_api_isolation ON public.customers
FOR ALL TO example_project_db_api
USING (owner_id = cubibase.current_user_id())
WITH CHECK (owner_id = cubibase.current_user_id());USINGlimits which rows the user can read, update, or delete.WITH CHECKlimits which rows the user can insert or update into: writing someone else’s id fails with403 forbidden.- The check runs inside PostgreSQL, not in application code you have to remember.
From JWT to rows
- The user signs in; the access token’s
subclaim is their user id. - Your app sends the token as
Authorization: Bearer …on a Data API call. - The engine verifies the token and sets
cubibase.user_idfor that transaction. - PostgreSQL applies the policy: the query only sees rows where
owner_idmatches.
What the policy does not do
- It is per-row ownership, not roles or teams. For richer rules — statuses, teams, published rows — write your own policies on the Policies screen.
- The user-column flag itself only exists at creation; an existing table can get an equivalent rule as a hand-written policy.
- It does not replace exposure switches: an unexposed operation is refused before any row is touched.
- Anonymous users work exactly like registered users — their id is real, so their rows are theirs.