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 roleWho uses itTypical policy
apiYour application’s end users (Data API)Restrict rows per user, per team, or per status
sqlYou, in the ConsoleFull 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

FieldMeaning
CommandALL, SELECT, INSERT, UPDATE, or DELETE — which statements the policy governs
USINGWhich existing rows are visible for SELECT, UPDATE, DELETE
WITH CHECKWhich new or updated rows are allowed for INSERT, UPDATE
PermissivePermissive policies combine with OR; restrictive policies combine with AND
Rolesapi, 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:

Example · published notes are readable by everyone
-- Command: SELECT · Role: api · USING:
status = 'published' OR owner_id = cubibase.current_user_id()
Example · users may only write their own rows
-- 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.

Additional resources