supabase-best-practices
Best practices for Supabase PostgreSQL, RLS policies, Edge Functions, and Realtime. Use when working with database schemas, queries, migrations, Row Level Security, storage, or any Supabase-related code.
- License 许可
- MIT
- 最近更新
- 2026-05-18
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- supabase-best-practices
- description
- Best practices for Supabase PostgreSQL, RLS policies, Edge Functions, and Realtime. Use when working with database schemas, queries, migrations, Row Level Security, storage, or any Supabase-related code.
03 SKILL.md 正文
Supabase Best Practices for Aurion Studio
Database Design
- Use UUIDs for primary keys (
gen_random_uuid()) - Always add
created_at TIMESTAMPTZ DEFAULT now()andupdated_atcolumns - Use snake_case for table and column names
- Add proper indexes for frequently queried columns
- Use
BIGINTfor credit/financial values (avoid floating point)
Row Level Security (RLS)
- ALWAYS enable RLS on every table:
ALTER TABLE [table] ENABLE ROW LEVEL SECURITY - Create policies for each operation (SELECT, INSERT, UPDATE, DELETE)
- Use
auth.uid()for user-scoped access - Pattern:
CREATE POLICY "Users can read own data" ON [table] FOR SELECT USING (auth.uid() = user_id) - Service role key bypasses RLS — never expose client-side
- Test policies: query as authenticated user AND as anon to verify isolation
Migrations
- File naming:
supabase/migrations/YYYYMMDD_description.sql - Always include rollback commands as comments
- Test migrations in a staging environment first
- Never modify existing migrations — create new ones
- Use transactions for multi-statement migrations
Queries
- Use parameterized queries ONLY (prevents SQL injection)
- Supabase client:
.from('table').select('*').eq('user_id', userId) - Avoid
.select('*')in production — select only needed columns - Use
.single()when expecting exactly one row - Handle errors:
const { data, error } = await supabase.from(...)
Edge Functions
- Keep functions small and focused
- Use the middleware pattern from
api/_lib/ - Validate all inputs at the boundary
- Return proper HTTP status codes
- Rate limit sensitive endpoints
Realtime
- Subscribe only to needed channels
- Unsubscribe on component unmount
- Use channel-specific subscriptions, not table-wide
- Handle reconnection gracefully
Storage
- Set bucket policies matching RLS patterns
- Use signed URLs for private files
- Validate file types and sizes before upload
- Clean up orphaned files periodically
Aurion-Specific Patterns
- Credits system:
user_creditstable with atomicdeduct_credits()function - Auth bridge: Clerk JWT →
TOOL_AUTH_SECRET→ Supabase RLS - Monthly reset: lazy check on
period_endindeduct_credits() - Reconciliation:
reconcile_credits()after each AI request
04 同仓库更多 Skills
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
vercel-react-view-transitions
Guide for implementing smooth, native-feeling animations using React's View Transition API (`<ViewTransition>` component, `addTransitionType`, and CSS view transition pseudo-elements). Use this skill whenever the user wants to add page transitions, animate route changes, create shared element animations, animate enter/exit of components, animate list reorder, implement directional (forward/back) navigation animations, or integrate view transitions in Next.js. Also use when the user mentions view transitions, `startViewTransition`, `ViewTransition`, transition types, or asks about animating between UI states in React without third-party animation libraries.
vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
vercel-composition-patterns
React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.
vercel-cli-with-tokens
Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".