Blog/Announcements

Row level security, functions and triggers on the canvas

Policies, functions, triggers and notes move out of migration files and onto the diagram, and follow every branch, merge and import.

Announcements5 min read

Some of the most important parts of a PostgreSQL schema never appear on a diagram: who can read which rows, what runs when a row changes, and the notes that explain why a column exists. They live in migration files. This release brings them onto the canvas.

Everything below uses one small table as the running example. It's a projects table with an id, an owner_id uuid holding the user who created it, a name, and an updated_at timestamptz. You want each person to see only their own projects, updated_at to stay current without the app remembering to set it, and a note on owner_id so the next person knows where the value comes from.

Row level security

Select the table and open the Inspector. On a PostgreSQL diagram it has a Security section, with a Row level security switch (Off or On) and the table's policies under it. Each policy has a name, a command (All commands, Select, Insert, Update or Delete), a kind (Permissive or Restrictive), the roles it applies to, and its using and with check expressions. Leave the roles blank and the policy applies to PUBLIC.

For the example, open "From template" and pick "Owners manage their rows". Owner templates are offered once per uuid column, with owner-sounding names (user_id, owner_id, author_id and the like) first, so choose owner_id. If RLS was off, adding a template turns it on, because a policy does nothing without it. The migration gets these statements:

ALTER TABLE "projects" ENABLE ROW LEVEL SECURITY;

CREATE POLICY "own rows" ON "projects"
  TO authenticated
  USING ((select auth.uid()) = owner_id)
  WITH CHECK ((select auth.uid()) = owner_id);

The templates are written for Supabase's roles and auth.uid(). Wrapping it in (select ...) means Postgres works it out once per statement rather than once per row.

A clause field only appears when the command can take it: a Select or Delete policy has no with check box, and an Insert policy has no using box. Switch a policy's command and any clause the new command can't take is dropped. Tables with RLS on carry a shield on their card, green when they have policies and amber when they don't.

Functions and triggers

Functions belong to the branch, like views. They live under Objects → Functions in the side panel, where "New function" adds one. A function has a name, arguments as you'd write them (p_user uuid, p_limit int default 10), what it returns, a language, a volatility (Volatile, Stable or Immutable), a Security definer switch, settings one per line, and the body.

Triggers belong to a table. In the Inspector's Triggers section, "Add trigger" gives you a name, when it fires (Before, After or Instead of), what it fires for (Each row, or once per Statement), the events (insert, update, delete, truncate), the function it runs, and an optional when (...) condition. Tables with triggers show a bolt and a count on their card, with the trigger names on hover.

For the example, add a function called touch_updated_at that returns trigger in plpgsql, then a Before trigger on update, for each row, that runs it. The migration writes the function before the trigger that needs it:

CREATE FUNCTION "touch_updated_at"()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
begin
  new.updated_at := now();
  return new;
end
$function$;

CREATE TRIGGER "projects_touch_updated_at"
  BEFORE UPDATE ON "projects"
  FOR EACH ROW
  EXECUTE FUNCTION touch_updated_at();

Rolling back reverses the order: the trigger is dropped first, then the function. Later changes follow Postgres's rules. A function whose body changes is written as CREATE OR REPLACE FUNCTION. One whose return type changes is dropped and created again, since Postgres won't replace it in place. A changed trigger is dropped and recreated.

A function is identified by its name and argument types, the way Postgres tells overloads apart. So int and integer count as the same argument. Dropping a function names its arguments without their defaults, so touch(p_limit int default 10, p_name text = 'x') goes with DROP FUNCTION "touch"(p_limit int, p_name text);.

Notes

Tables and columns take a note of up to 4,000 characters. The table's note sits in the Inspector under Note; a column's opens from its "Add a note" toggle. A small notebook marker on the card shows the note on hover, and the "Data dictionary (Markdown)" export includes every note.

Each engine stores comments its own way, and the SQL follows. On PostgreSQL and Oracle, a note on users and one on users.email become:

COMMENT ON TABLE "users" IS 'Accounts';

COMMENT ON COLUMN "users"."email" IS 'Used to sign in';

MySQL keeps a column's comment in its definition, so changing it restates the whole column, and a table's comment is a table option:

ALTER TABLE `users` MODIFY COLUMN `email` TEXT NOT NULL COMMENT 'Used to sign in';

ALTER TABLE `users` COMMENT = 'Accounts';

SQL Server has no comment statement. The app writes the MS_Description extended property instead, with sp_addextendedproperty the first time, then sp_updateextendedproperty or sp_dropextendedproperty:

EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'Accounts', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'users';

SQLite has no comments at all, so a migration that changes a note there says -- SQLite has no comments; skipped: the note on users.

What Health checks

The Health tab (under Insights) looks at all of this. For functions and triggers it flags:

  • a trigger whose function isn't one of the branch's functions (fine if it lives elsewhere in the database, but now you know to check)
  • a trigger whose function doesn't return trigger
  • a security definer function with no fixed search path

That last one matters because a function running as its owner resolves unqualified names through the caller's search_path. Set search_path="" in the function's settings and name objects with their schema, and the migration writes SET search_path TO '' into the function.

For RLS, Health flags a table with RLS on and no policies, policies on a table with RLS off, a table left without RLS while others have it, and a policy clause that doesn't parse.

They travel with the rest

All of it follows branches, merges, version snapshots and imports. A merge review lists a changed policy, function, trigger or note as its own line you can tick or untick. Change a policy's roles or clauses and the migration writes ALTER POLICY; change its command or kind and it drops the policy and creates it again, since ALTER POLICY can't do that.

Reading goes the other way. A live PostgreSQL import reads policies from pg_policies, functions from pg_proc and triggers from pg_trigger. Paste SQL that mentions row level security and the parser reads the policies too. Checking out a Git commit replays its migrations, functions and triggers included. Drizzle exports write policies with pgPolicy, and .enableRLS() for a table that has RLS on but no policies.

PostgreSQL only

RLS, functions and triggers are modelled for PostgreSQL, including hosts like Supabase and Neon. On other engines the Security section and the Functions tab don't appear, and a migration that would need them says so instead of writing something that won't run:

-- mysql has no row level security; skipped: users
-- MySQL functions and triggers aren't written from the model; skipped: function touch

Notes work everywhere except SQLite.

More announcements

  • Convex schemas, in and out

    19 November 2026 · 6 min read

    Export a diagram as convex/schema.ts from any engine, paste one in, or check one out from a repository, and what happens to the parts Convex can't hold.

  • Snippets: drop-in table sets that stay up to date

    10 November 2026 · 6 min read

    About a hundred ready-made table sets for payments, auth, teams and more, inserted into the schema you already have and updated without losing your edits.

  • A vault we can't open, and a local agent

    6 November 2026 · 6 min read

    Database credentials sealed in your browser with a workspace key our servers never see, and a small agent that reads databases from your own machine.

Try it on your own schema

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