Blog/Guides

Row level security you can read at a glance

Postgres policies live in migration files where nobody looks at them. Here is how to keep them next to the tables they protect.

Guides6 min read

Postgres row level security is one of the best tools a multi-tenant app has. Turn it on for a table, add policies, and the database itself refuses to hand one customer's rows to another, whatever the application code does.

It also has a visibility problem. Policies are written once, in a migration, and then nobody reads them again. Six months later the question "who can read the invoices table?" means grepping a migrations folder and replaying the history in your head.

This post is a practical guide to designing policies in Bright Web Data Modeller, using a small team workspace schema as the example.

Policies belong with the table

In the app a table's policies sit on the table, next to its columns. Select a table and the Inspector's Security section shows the Row level security switch and every policy the table has: its name, the command it covers, whether it's Permissive or Restrictive, the roles it applies to (blank means PUBLIC), and its using and with check expressions.

Under the switch, one line tells you what the current state means in practice:

  • RLS off, no policies: anyone with table privileges can read and write every row.
  • RLS off, with policies: these policies do nothing until row level security is on.
  • RLS on, no policies: only the service role can read or write rows until a policy allows more.
  • RLS on, with policies: rows are visible only where a policy allows.

On the canvas, a table with RLS on carries a shield. Hover it for the policy count; it's amber when there are none.

How Postgres reads a set of policies

Two rules decide almost everything, and they're worth having straight before you write anything.

First, each command uses different clauses. using decides which existing rows a statement can see or touch; with check decides whether a row being written is allowed. The Inspector only shows the boxes a command can take:

Commandusingwith check
All commandsyesyes
Selectyesno
Insertnoyes
Updateyesyes
Deleteyesno

Change a policy's command and any clause the new one can't take is cleared, because Postgres would refuse it.

Second, permissive policies for the same command and role are combined with OR: a row passes if any one of them allows it. Restrictive policies are combined with AND on top of that, so every restrictive policy must also pass. Use permissive policies to grant access and restrictive ones to narrow it.

A worked example: a team workspace

Take four tables: orgs, org_members (org_id, user_id uuid, role), projects (with an org_id) and tasks (with a project_id and an org_id). The rule you want is simple to say: you see a project or a task if you're a member of its org.

Write that check once, as a function. Under Objects → Functions, add is_member with the argument p_org uuid, returning boolean, language sql, Stable, with Security definer on and the setting search_path="":

CREATE FUNCTION "is_member"(p_org uuid)
RETURNS boolean
LANGUAGE sql
STABLE
SECURITY DEFINER
SET search_path TO ''
AS $function$
select exists (
  select 1 from public.org_members
  where org_id = p_org and user_id = (select auth.uid())
)
$function$;

The function runs as its owner, so it can read org_members without that table's own policies getting in the way. That also avoids the classic mistake of an org_members policy that queries org_members, which Postgres stops with an infinite recursion error. Because it runs with elevated rights, the empty search_path and the schema-qualified public.org_members matter. Health warns about any security definer function without a fixed search path.

Now the policies. On projects, add a policy called "members read", command Select, role authenticated, using public.is_member(org_id):

CREATE POLICY "members read" ON "projects"
  FOR SELECT
  TO authenticated
  USING (public.is_member(org_id));

On tasks, let members add rows, but only into an org they belong to. An Insert policy has only a with check:

CREATE POLICY "members add tasks" ON "tasks"
  FOR INSERT
  TO authenticated
  WITH CHECK (public.is_member(org_id));

Then narrow. Say archived projects should disappear for everyone, whatever else allows them. That's a Restrictive Select policy:

CREATE POLICY "hide archived" ON "projects"
  AS RESTRICTIVE
  FOR SELECT
  TO authenticated
  USING (archived_at is null);

Read the three together on the projects card and the answer to "who can read projects?" is right there: members of the org, and only for projects that aren't archived.

Templates and the tenant kit

Most policies follow a handful of shapes, so "From template" in the Security section offers four:

  • Owners manage their rows
  • Owners read their rows
  • Signed-in users read every row (Select, authenticated, using true)
  • Anyone reads every row (Select, anon and authenticated, using true)

The two owner templates compare (select auth.uid()) with a column. They're offered once for each uuid column on the table, with owner-sounding names such as user_id, owner_id, author_id or created_by listed first; a table with no uuid column doesn't get them. The roles field suggests Supabase's anon, authenticated and service_role as you type. Adding a template to a table with RLS off turns it on.

If your app isolates tenants with a session setting rather than auth.uid(), the Tenant column kit does the whole job across many tables at once. Select the tables, choose "Column kit" in the Inspector (or "Add tenant columns…" in the command palette), and point its Tenants placeholder at your orgs, tenants or workspaces table. Each table gets a tenant_id foreign key with on delete cascade, an index, RLS on, and a policy named after the table. On invoices that's:

CREATE POLICY "invoices_tenant_isolation" ON "invoices"
  TO PUBLIC
  USING (tenant_id = current_setting('app.tenant_id', true)::uuid)
  WITH CHECK (tenant_id = current_setting('app.tenant_id', true)::uuid);

Your app sets app.tenant_id for each request. The kit's changes open in the merge review first, so you see every column, index and policy before anything is applied.

What Health catches

The Health tab under Insights checks every table on a PostgreSQL diagram:

  • RLS on and no policies. Only the service role (and the table's owner) can read or write it, which is rarely what anyone meant.
  • Policies, but RLS off. The policies do nothing at all.
  • RLS off on one table while others have it on. Usually a table someone forgot.
  • A using or with check clause that doesn't parse.

The second one is the dangerous one, because everything looks right in a code review. The last is a syntax check only: clauses often read other tables, so names the diagram doesn't know aren't flagged.

Changing policies later

Policies take part in branches and merges like everything else. A merge review lists each policy change as its own line, written the way create policy reads (for example select to authenticated using (...)), and the migration picks the smallest statement Postgres allows. A change of roles or clauses becomes ALTER POLICY; a change of command or kind, or removing a clause, drops the policy and creates it again, since ALTER POLICY can't do those. Policies are dropped before the migration drops any columns, so a policy never outlives a column it reads.

Drizzle exports write each policy as pgPolicy in the table's extra config. The "members read" policy comes out as:

pgPolicy("members read", { for: "select", to: "authenticated", using: sql`public.is_member(org_id)` }),

A table with RLS on and no policies gets .enableRLS() instead, since drizzle-kit turns RLS on by itself for a table with policies. Imports work the other way: a live PostgreSQL import reads policies from pg_policies, and pasted SQL that mentions row level security brings its policies across.

Row level security is a Postgres feature, so all of this applies to PostgreSQL diagrams (including Supabase and Neon). Other engines don't have an equivalent: the Security section isn't shown there, and a migration says it skipped RLS rather than pretending.

More guides

  • What the generated migration actually does

    17 November 2026 · 8 min read

    How a diagram's changes become migration SQL for six engines, and the places where each engine needs something other than ALTER TABLE.

  • Give your schema tool a read-only login

    14 November 2026 · 6 min read

    A tool that reads table definitions shouldn't hold a login that can read every row. How the app writes a catalog-only login for each engine, and what it does with the connection.

  • Review schema changes the way you review code

    8 November 2026 · 5 min read

    A dropped column deserves the same scrutiny as a deleted function. Branches and merge requests for your data model, and what a reviewer sees.

Try it on your own schema

One diagram with two branches, no card needed. Upgrade when your team needs more.