Also available: Markdown version · llms.txt · full site content
Database
Policies
The Policies screen manages Row Level Security on your tables: turn RLS on or off per table, and write your own PostgreSQL policies with USING and WITH CHECK expressions.
How policies fit the role model
Every project has two query roles. The api role serves Data API requests and is subject to your policies. The sql role serves the Console (row browser, SQL editor) and normally has a permissive developer policy so you can manage every row.
| Target role | Who uses it | Typical policy |
|---|---|---|
api | Your application’s end users (Data API) | Restrict rows per user, per team, or per status |
sql | You, in the Console | Full access for administration |
Tables created with a user column already carry an isolation policy for the api role. The Policies screen lists those policies alongside any you add, and lets you edit or drop them.
Enabling and disabling RLS
- Each table row shows whether RLS is enabled and forced.
- Disabling RLS makes every grant effective for every row — the policies stay stored but stop being applied.
- FORCE RLS applies policies even to the table owner. CubiBase enables it with RLS so nothing slips past by ownership.
Writing a policy
| Field | Meaning |
|---|---|
| Command | ALL, SELECT, INSERT, UPDATE, or DELETE — which statements the policy governs |
USING | Which existing rows are visible for SELECT, UPDATE, DELETE |
WITH CHECK | Which new or updated rows are allowed for INSERT, UPDATE |
| Permissive | Permissive policies combine with OR; restrictive policies combine with AND |
| Roles | api, sql, or both |
Expressions are ordinary PostgreSQL boolean expressions. Reference the signed-in user with cubibase.current_user_id(), which returns the verified JWT subject for the request:
-- Command: SELECT · Role: api · USING:
status = 'published' OR owner_id = cubibase.current_user_id()-- Command: INSERT · Role: api · WITH CHECK:
owner_id = cubibase.current_user_id()- INSERT policies accept only WITH CHECK; SELECT and DELETE accept only USING.
- For ALL and UPDATE, omitting WITH CHECK reuses the USING expression as the write check.
- Expressions must be a single expression — stacked statements are rejected with
400 validation_error. - Bare column names are checked against the table, so a typo fails fast instead of at query time.
Editing and dropping
- Editing expressions or roles uses ALTER POLICY in place.
- Changing the command or the permissive flag recreates the policy inside one transaction, so the table is never left unprotected mid-change.
- Dropping a policy takes effect immediately for new requests.