Supabase RLS and Postgres Migration Review: Indexes, Locks

A SKILL.md that reviews Supabase or Postgres migrations and queries for missing row level security, leaky policies, unindexed foreign keys and table-locking changes, with fix SQL.

Skill prompt for Claude Code and Codex

Prompt

Installs to .agents/skills/supabase-rls-and-postgres-migration-review-indexes-locks/

mkdir -p .agents/skills/supabase-rls-and-postgres-migration-review-indexes-locks && curl -sL "https://prompts-gpt.com/prompts/supabase-rls-and-postgres-migration-review-indexes-locks/raw" -o .agents/skills/supabase-rls-and-postgres-migration-review-indexes-locks/SKILL.md
SKILL.md
Preview
---
name: supabase-rls-and-postgres-migration-review-indexes-locks
description: "A SKILL.md that reviews Supabase or Postgres migrations and queries for missing row level security, leaky policies, unindexed foreign keys and table-locking changes, with fix SQL."
---

# Supabase RLS and Postgres Migration Review: Indexes, Locks

A SKILL.md that reviews Supabase or Postgres migrations and queries for missing row level security, leaky policies, unindexed foreign keys and table-locking changes, with fix SQL.

## Prompt

```
---
name: postgres-supabase-review
description: Reviews Postgres and Supabase schema changes, migrations, policies and queries for security holes, missing indexes and locking risks before they reach production, and writes fix SQL. Use when asked to "review this migration", "check my RLS policies", "is my Supabase schema secure", "why is this query slow" or "review the database changes in this PR".
---

# Postgres and Supabase review

## Scope

1. List the changed SQL: `git diff --name-only main...HEAD` filtered to `supabase/migrations/`, other migration folders and `.sql` files. Also collect client code that calls the database (supabase-js queries, ORM calls) in the same diff.
2. If a local stack is running, use it read-only: `supabase db lint` and `EXPLAIN` on the queries you flag. Never connect to production.

## Checks

Security (Supabase)
- Every new table in an exposed schema (usually public) has row level security enabled and at least one policy per operation it needs.
- Policies use `using` for rows read and `with check` for rows written; an update policy without `with check` lets users move rows to other owners.
- No policy is `using (true)` on user data unless the table is meant to be public.
- Policies call `(select auth.uid())` rather than `auth.uid()` so it is evaluated once per query.
- Security definer functions set `search_path` and live outside exposed schemas; views over protected tables use `security_invoker`.
- The service role key never appears in browser or mobile code.

Performance
- Every foreign key column and every column used in a policy or frequent filter has an index.
- New queries do not select `*` across joins or page with large OFFSET values.

Locking and safety
- Index creation on large tables uses `create index concurrently` in its own migration outside a transaction.
- Type changes, new NOT NULL columns without a constant default, and new foreign keys on big tables are flagged as blocking; suggest the add-nullable, backfill, validate pattern.
- Destructive changes (drop column, drop table, rename) have a rollback plan and no code still reading the old name.

## Output

A findings table: severity (Blocker, Should fix, Note), file:line, the problem in one sentence, and the fix SQL. Then a list of checks that passed, and anything you could not verify without data volumes.

## Stop and ask

- A fix needs table sizes or production statistics you do not have.
- A migration has already run in production: propose a new migration, never edit the old one.
```

## Usage Notes

Save as .claude/skills/postgres-supabase-review/SKILL.md, or .agents/skills/ for Codex, Cursor and Gemini CLI. Ask: "review the database changes in this PR". It reads files and a local stack only; it never touches production.

Example output

Example for: a PR adding a projects and tasks feature to a Supabase app, 2 migrations and 3 client files.

SeverityLocationProblemFix
Blocker20261124_tasks.sql:12RLS is not enabled on public.tasks, so any signed-in user can read every task through the APIalter table public.tasks enable row level security; plus the policies below
Blocker20261124_projects.sql:31Update policy has using but no with check, so a member can set owner_id to someone elsecreate policy "owners update" on public.projects for update using ((select auth.uid()) = owner_id) with check ((select auth.uid()) = owner_id);
Blockersrc/lib/admin.ts:4Service role key read from a NEXT_PUBLIC_ variable, which ships to the browserMove admin calls to a server route; use a non-public env var
Should fix20261124_tasks.sql:8tasks.project_id is a foreign key with no index; policies and joins filter on itcreate index concurrently tasks_project_id_idx on public.tasks (project_id); in a separate migration
Should fix20261124_projects.sql:40Policy calls auth.uid() directly; evaluated per rowWrap it: (select auth.uid())
Notesrc/app/tasks/page.tsx:22.select('*') on tasks joined to projectsSelect the 5 columns the page shows

Passed: security definer function get_project_stats sets search_path; no destructive changes; no edits to existing migrations.

Could not verify: whether adding the NOT NULL column projects.status with a constant default is safe on your table size; it is fast on Postgres 11 and later, but confirm the server version.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • It checks for the update policy without with check, a common Supabase hole that a quick read of the policies misses.
  • Every finding comes with fix SQL and a file:line, so it can go straight into a review comment.
  • Locking checks catch migrations that pass on a small dev database and block writes on a large production table.

Save as .claude/skills/postgres-supabase-review/SKILL.md, or .agents/skills/ for Codex, Cursor and Gemini CLI. Ask: "review the database changes in this PR". It reads files and a local stack only; it never touches production.

Common edits

  • Remove the Supabase section for plain Postgres apps and add your ORM's migration folder to the scope step.
  • Add a row count threshold, such as 1 million rows, above which any blocking change is a Blocker rather than Should fix.

Reuse it: Use in a workflowAdapt in the builder

More in Coding
Coding

Security Review of a Code Snippet: Ranked Findings With Exploit Path and Fix

Reviews pasted code for injection, broken authorization, secrets, SSRF and similar flaws, and returns only real findings ranked by severity, each with a one-line exploit path and fixed code.

Coding

Pull Request Review with Merge Recommendation

Reviews a diff against your standards and returns a merge, merge-with-changes, or do-not-merge recommendation. Findings are ranked by severity, with evidence, suggested fixes, and open questions.

Coding

Audit a stale README against project configuration

Spot outdated setup steps, dead commands, and missing dependencies between your README and your actual configuration files.

Coding

Split a large pull request into reviewable commits

Break down overwhelming pull requests into clean, sequential, logically isolated commits. Use it when code reviews stall due to sprawling diffs.

Coding

Write a guided walkthrough for a complex pull request

Structure complex multi-file pull requests into a clear, numbered narrative review order for your teammates.

Coding

Explain Any Regex Token by Token with Matching and Failing Examples

Get a token-by-token table explaining your regex, plus strings that match, nearly match and fail, and a clear catastrophic backtracking risk check with a safer rewrite.