supabase-usage
npx machina-cli add skill fcakyon/claude-codex-settings/supabase-usage --openclawSupabase Database Patterns
Patterns for working with Supabase databases including Auth, Row Level Security, table relationships, and query best practices.
Overview
- MCP Tools: Query and explore database structure
- Authentication: User management, sessions, auth tables
- Row Level Security: Policy patterns for data access control
- Table Relationships: Foreign keys, joins, nested queries
- Query Patterns: Filtering, pagination, performance
MCP Tools
Available tools for database exploration:
mcp__supabase__list_tables- List all tables in the databasemcp__supabase__get_table_schema- Get schema for a specific tablemcp__supabase__execute_sql- Run read-only SQL queries
Workflow:
- Start with
list_tablesto understand database structure - Use
get_table_schemato inspect columns and types - Use
execute_sqlfor custom queries (read-only)
Best Practices
DO
- ✓ Enable RLS on all public tables
- ✓ Use
(select auth.uid())in RLS policies for performance - ✓ Add indexes on RLS-checked columns
- ✓ Specify roles with
TO authenticatedin policies - ✓ Use
on delete cascadefor foreign keys to auth.users - ✓ Use cursor-based pagination for large datasets
- ✓ Select only needed columns:
.select('id, name')not.select('*')
DON'T
- ✗ Store sensitive data without RLS
- ✗ Use
auth.uid()directly in policies (use(select auth.uid())) - ✗ Create policies without specifying roles
- ✗ Forget indexes on frequently filtered columns
- ✗ Use offset pagination for deep pages (>1000 rows)
- ✗ Expose auth.users directly via API (use public profiles table)
Quick Reference
Common Filters
| Filter | JavaScript | Python |
|---|---|---|
| Equals | .eq('col', val) | .eq("col", val) |
| Not equals | .neq('col', val) | .neq("col", val) |
| Greater than | .gt('col', val) | .gt("col", val) |
| Greater or equal | .gte('col', val) | .gte("col", val) |
| Less than | .lt('col', val) | .lt("col", val) |
| Less or equal | .lte('col', val) | .lte("col", val) |
| Pattern match | .ilike('col', '%val%') | .ilike("col", "%val%") |
| In list | .in('col', [a,b]) | .in_("col", [a,b]) |
| Is null | .is('col', null) | .is_("col", "null") |
| OR | .or('a.eq.1,b.eq.2') | .or_("a.eq.1,b.eq.2") |
Auth Tables Quick Reference
| Table | Key Columns |
|---|---|
auth.users | id, email, phone, created_at, last_sign_in_at, raw_user_meta_data |
auth.sessions | id, user_id, created_at, updated_at |
auth.identities | id, user_id, provider, identity_data |
RLS Policy Template
create policy "policy_name" on table_name
to authenticated -- or anon, or specific role
for select -- select, insert, update, delete, or all
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id ); -- for insert/update
Additional Resources
For detailed patterns and code examples, consult:
references/auth.md- Authentication with JS/Python SDK, user profilesreferences/rls.md- Row Level Security policies and performance tipsreferences/relationships.md- Table relationships and nested queriesreferences/query-patterns.md- Filtering, pagination, counting, indexes
Source
git clone https://github.com/fcakyon/claude-codex-settings/blob/main/plugins/supabase-tools/skills/supabase-usage/SKILL.mdView on GitHub Overview
This skill covers patterns for working with Supabase databases, including authentication, Row Level Security (RLS), table relationships, and common query patterns. It maps MCP Tools like list_tables, get_table_schema, and execute_sql to practical workflows for exploring structure, securing data, and optimizing queries.
How This Skill Works
The skill coordinates MCP Tools to interact with your Supabase database: list tables to understand structure, inspect a table's schema to learn columns and types, and run read-only SQL queries for verification. It also emphasizes RLS, indexes, and pagination as core patterns, guiding you from discovery to secure, efficient data access.
When to Use It
- You need to list Supabase tables or inspect schema to map relationships.
- You want to run read-only queries, test filters, or experiment with pagination.
- You are designing or evaluating Row Level Security (RLS) policies and auth flows.
- You need guidance on table relationships, foreign keys, and joins across tables.
- You seek best practices for indexing, cursor-based pagination, and query patterns.
Quick Start
- Step 1: Start with mcp__supabase__list_tables to understand the database structure.
- Step 2: Use mcp__supabase__get_table_schema for a target table, then mcp__supabase__execute_sql for read-only queries.
- Step 3: Review RLS, indexing, and pagination best practices, and adjust policies and columns accordingly.
Best Practices
- Enable RLS on all public tables
- Use (select auth.uid()) in RLS policies for performance
- Add indexes on RLS-checked columns
- Specify roles with TO authenticated in policies
- Use cursor-based pagination for large datasets
Example Use Cases
- List all tables and inspect schemas to map relationships between users, posts, and profiles.
- Query with filters and implement cursor-based pagination for a posts feed.
- Create an RLS policy using (select auth.uid()) to restrict access to a user's own data.
- Define foreign keys and joins to fetch related records (e.g., users → profiles → posts).
- Run read-only SQL via execute_sql to explore data without mutating it.