In Supabase, your policies are the authorization layer

In a Supabase project the browser talks to Postgres directly. The Data API exposes every table, view and function in the exposed schemas (public by default) to anyone holding the project’s publishable key, and each request runs as the role anon when signed out or authenticated when signed in. There is no application server in the middle deciding what comes back.

That means your grants and Row Level Security policies are not a safety net on top of an authorization layer. They are the authorization layer. A table without a policy is a public endpoint, and a policy nobody ran is a guess.

// Detect dark theme var iframe = document.getElementById('tweet-2122066551289368720-190'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2122066551289368720&theme=dark" }

This keeps happening at scale, and it keeps happening to teams who thought the schema was fine because the app looked fine.

Install it

npx claude-code-templates@latest --agent database/supabase-schema-architect 

That writes .claude/agents/supabase-schema-architect.md in the project. A project copy wins over one in ~/.claude/agents/, so a team can pin its own version.

Two things in its frontmatter are worth knowing before you run it. tools is set to Read, Write, Edit, Bash, Glob, Grep, and in a subagent tools is an allowlist that restricts: this agent cannot reach your MCP servers, which an agent that writes SQL and starts a database probably should not. model: inherit means it runs on whatever model the session is on, and since 2.1.251 that frontmatter value wins over CLAUDE_CODE_SUBAGENT_MODEL.

One correction to the catalog entry: its description opens with “MUST BE USED”, which is prompt text, not a documented trigger. The phrase Anthropic documents for proactive delegation is “use proactively”. Delegation still comes down to Claude reading that description and deciding, so ask for the agent by name the first few times.

// Detect dark theme var iframe = document.getElementById('tweet-2122937536565641711-36'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2122937536565641711&theme=dark" }

It does not hand back SQL it has not run

This is what separates it from a prompt that knows Supabase trivia. Before it reports, it applies the migration and acts as real users.

With Docker it runs supabase start, supabase db reset, supabase test db for pgTAP tests, and supabase db advisors for Supabase’s own security and performance checks. Without Docker it starts a scratch Postgres with initdb, creates only the parts of Supabase the migration touches (the anon, authenticated and service_role roles, an auth schema, and auth.uid() and auth.jwt() shims that read request.jwt.claims), and grants nothing else, so the test also proves your explicit grants.

Then it becomes each user, inside a transaction it rolls back:

begin; set local role authenticated; select set_config('request.jwt.claims', json_build_object('sub', '<user uuid>', 'role', 'authenticated')::text, true); select count(*) from public.tasks; rollback; 

It seeds two users in two organizations and shows, per table, that a member reads their own organization’s rows and none of the other’s, that inserting into the other organization fails, that updating a row to move it across tenants fails, that a member cannot change their own role, and that anon reads nothing it should not.

The line worth stealing even if you never install this agent: a superuser skips RLS, so a test that never switches role proves nothing. That is why most hand-written policy tests pass.

One caveat the post does not mention: that run is conditional. If there is no Docker and no Postgres it can start, the agent says so plainly and lists what is untested instead of pretending. Read that part of its report before you deploy.

The mistakes it is written against

Its instructions are a list of things that are easy to get wrong in exactly this stack:

  1. insert ... returning (supabase-js .insert().select()) checks the new row against the SELECT policy during the insert, before any after insert trigger runs. That is why “create an organization and become its owner” fails with new row violates row-level security policy. The fix is created_by uuid default auth.uid() plus a SELECT policy that matches it.
  2. A policy on memberships that queries memberships raises infinite recursion detected in policy. That lookup belongs in a security definer function in a private schema, with set search_path = '' and execute revoked from anon.
  3. Never authorize on user_metadata. Users can change it themselves with updateUser. Use app_metadata or a table.
  4. Views run as their owner and bypass RLS unless you create them with (security_invoker = true).
  5. On UPDATE, using says which rows may change and with check says what they may become. A with check looser than using lets a user move a row into another tenant. Column privileges stop the writes a row policy cannot express, like a member editing their own role.
  6. An unwrapped auth.uid() is evaluated once per row. (select auth.uid()) is evaluated once per query. Supabase’s own linter flags this as auth_rls_initplan.
  7. supabase db diff misses view security_invoker, column privileges, alter policy and alter publication. Those get written by hand.

It also hands off instead of guessing: large online migrations go to database-architect, query tuning to postgres-pro, Realtime load to supabase-realtime-optimizer.

Where the agents live

// Detect dark theme var iframe = document.getElementById('tweet-2015605651267866628-502'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=2015605651267866628&theme=dark" }

You can follow me on my social media: