data-supabase-patterns

Applies Postgres and Supabase best practices for indexing, RLS, pooling, and migrations.

3|3|Updated Apr 23, 2026
One-click install
npx skills add https://github.com/joaoguirunas/team-os --skill data-supabase-patterns-joaoguirunas
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: data-supabase-patterns
Source: https://github.com/joaoguirunas/team-os/tree/main/.claude/skills/data-supabase-patterns
Command: npx skills add https://github.com/joaoguirunas/team-os --skill data-supabase-patterns-joaoguirunas

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Slow queries, insecure tables, connection exhaustion, and risky migrations are the most common failure modes in Supabase and Postgres projects. This Skill provides a distilled, prioritized rulebook so engineers write performant SQL, secure RLS policies, and zero-downtime migrations from the start instead of debugging production incidents later. ## Core Features & Use Cases - Query Performance Rules: Indexing strategies (composite, partial, covering, expression indexes), keyset pagination, and EXPLAIN (ANALYZE, BUFFERS) diagnostics for slow queries. - Security & RLS Patterns: Performant row-level security using initPlan subselects, indexed policy columns, SECURITY DEFINER helpers, and pinned search_path for functions. - Safe Migrations & Connection Management: Zero-downtime migration playbooks (CONCURRENTLY, NOT VALID constraints, expand/contract), Supavisor transaction-mode pooling for serverless, and statement timeouts. - Use Case: A developer writing a new migration for a multi-tenant Supabase app uses this Skill to add RLS policies with (SELECT auth.uid()), index the tenant FK, create indexes CONCURRENTLY, and validate the query plan before merging. ## Quick Start Review my Supabase migration and RLS policies for performance and security issues using the Postgres best practices checklist.

Frequently Asked Questions about data-supabase-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make Supabase RLS policies faster?▼

Wrap auth functions in a subselect, e.g. USING ((SELECT auth.uid()) = user_id), so they are evaluated once per query instead of per row. Also index the columns referenced by policies and specify the role with TO authenticated to short-circuit anon traffic.

How do I optimize slow Postgres queries in Supabase?▼

Start with pg_stat_statements to find top queries by total_exec_time, then run EXPLAIN (ANALYZE, BUFFERS) on the suspect query. Look for sequential scans on large tables, add indexes on WHERE/JOIN/ORDER BY columns, and use keyset pagination instead of OFFSET for deep pages.

Should serverless functions use direct Postgres connections?▼

No. Serverless and edge functions must use the transaction-mode pooler (Supavisor, port 6543), since each invocation would otherwise hold a Postgres backend. Note that transaction mode does not support prepared statements or session-level state.

How do I add a NOT NULL column to a large table without downtime?▼

Use a three-step approach: add the column as nullable (instant), backfill values in batches, then set NOT NULL after validation. Create indexes with CREATE INDEX CONCURRENTLY and add constraints as NOT VALID followed by VALIDATE CONSTRAINT to avoid long locks.

Why is my index not being used in Postgres?▼

Wrapping an indexed column in a function, such as WHERE lower(email) = $1, disables the index. Create an expression index on the function result instead, e.g. CREATE INDEX ON users (lower(email)), and verify the plan with EXPLAIN ANALYZE.

When should I avoid UUID primary keys in Postgres?▼

Avoid UUIDv4 as the clustered primary key of very large tables because random ordering causes index bloat and poor cache locality. Prefer bigint GENERATED ALWAYS AS IDENTITY or UUIDv7, which preserves insertion ordering.