Agent skill
supabase-sql
Clean and format SQL migrations for Supabase - idempotency, RLS policies, formatting, schema fixes. Use when: fix this SQL, clean migration, RLS policy, Supabase schema, format postgres, prepare for SQL Editor, idempotent migration.
Install this agent skill to your Project
npx add-skill https://github.com/ScientiaCapital/skills/tree/main/active/supabase-sql-skill
SKILL.md
<quick_start> Clean any SQL migration:
- Fix typos (
-→--for comments) - Add idempotency (
IF NOT EXISTS,DROP ... IF EXISTS) - Fix RLS policies (service role uses
TO service_role, not JWT checks) - Remove dead code (unused enums)
- Standardize casing (
NOW(),TIMESTAMPTZ) - Add dependencies comment at end
DROP POLICY IF EXISTS "Policy name" ON table_name;
CREATE POLICY "Policy name" ON table_name ...
</quick_start>
<success_criteria> SQL cleanup is successful when:
- All policies and triggers use
DROP ... IF EXISTSbeforeCREATE - Service role policies use
TO service_role(not JWT checks) - Indexes use
IF NOT EXISTS - No unused enums remain
- Dependencies listed at end of migration
- SQL runs without errors in Supabase SQL Editor </success_criteria>
<core_patterns> Clean SQL migrations for direct paste into Supabase SQL Editor.
Cleanup Checklist
Run through each item:
- Fix typos - Common:
-instead of--on comment lines - Add idempotency -
IF NOT EXISTSon indexes,DROP ... IF EXISTSbefore policies/triggers - Remove dead code - Enums created but never used (TEXT + CHECK often preferred)
- Fix RLS policies - Service role must use
TO service_role, not JWT checks - Standardize casing -
NOW()notnow(),TIMESTAMPTZnottimestamptz - Remove clutter - Verbose RAISE NOTICE blocks, redundant comments, file path headers
- Validate dependencies - List required tables at end
Output Format
-- ============================================
-- Migration Name
-- Created: YYYY-MM-DD
-- Purpose: One-line description
-- ============================================
-- ============================================
-- Table Name
-- ============================================
CREATE TABLE IF NOT EXISTS ...
-- ============================================
-- Indexes
-- ============================================
CREATE INDEX IF NOT EXISTS ...
-- ============================================
-- Row Level Security
-- ============================================
ALTER TABLE ... ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS "..." ON ...;
CREATE POLICY "..." ON ...
-- ============================================
-- Functions
-- ============================================
CREATE OR REPLACE FUNCTION ...
-- ============================================
-- Triggers
-- ============================================
DROP TRIGGER IF EXISTS ... ON ...;
CREATE TRIGGER ...
Common Fixes
RLS Policy for Service Role
-- WRONG (doesn't work reliably)
CREATE POLICY "Service role access" ON my_table
FOR ALL
USING (auth.jwt() ->> 'role' = 'service_role');
-- CORRECT
CREATE POLICY "Service role access" ON my_table
FOR ALL
TO service_role
USING (true)
WITH CHECK (true);
Idempotent Policies
-- Always drop before create
DROP POLICY IF EXISTS "Policy name" ON table_name;
CREATE POLICY "Policy name" ON table_name ...
Idempotent Triggers
DROP TRIGGER IF EXISTS trigger_name ON table_name;
CREATE TRIGGER trigger_name ...
Unused Enums
If you see enum created but table uses TEXT CHECK (...) instead, remove the enum:
-- DELETE THIS - never used
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'my_enum') THEN
CREATE TYPE my_enum AS ENUM ('a', 'b', 'c');
END IF;
END$$;
-- Table actually uses TEXT with CHECK (keep this)
status TEXT NOT NULL CHECK (status IN ('a', 'b', 'c'))
Dependencies Section
Always end with dependencies note if tables are referenced:
-- Dependencies: businesses, call_logs, subscription_plans
-- Requires function: update_updated_at_column()
Reference Files
reference/rls-patterns.md- Common RLS policy patterns for Supabasereference/function-patterns.md- Trigger functions, atomic operations
Emit Outcome Sidecar
As the final step, write to ~/.claude/skill-analytics/last-outcome-supabase-sql.json:
{"ts":"[UTC ISO8601]","skill":"supabase-sql","version":"1.0.0","variant":"default",
"status":"[success|partial|error]","runtime_ms":[estimated ms from start],
"metrics":{"migrations_written":[n],"tables_modified":[n],"rls_policies_created":[n]},
"error":null,"session_id":"[YYYY-MM-DD]"}
Use status "partial" if some stages failed but results were produced. Use "error" only if no output was generated.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
project-context
Maintains project context and progress tracking across Claude sessions. Use at session start to load context, on session end to save progress. Triggers: load project context, save context, end session, what was I working on, switch to project, done for today.
workflow-enforcer-skill
Enforces workflow discipline across ALL projects. Ensures Claude checks for specialized agents before responding, announces skill/agent usage, and creates TodoWrite todos for multi-step tasks. Triggers: automatic on all sessions, use the right agent, follow workflow.
gtm-pricing
B2B go-to-market strategy, pricing models, ICP development, positioning, and competitive intelligence. Use when planning GTM strategy, setting pricing, defining ICP, or evaluating opportunities.
subagent-teams
Orchestrate in-session Task tool teams for parallel work. Fan-out research, implementation, review, and documentation across subagents. Use when: parallel tasks, fan-out, subagent team, Task tool, in-session agents.
planning-prompts
Comprehensive skill for project planning and prompt engineering. Covers hierarchical plans (briefs, roadmaps, phases), Claude-to-Claude meta-prompts, and multi-stage workflows. Use when: planning, prompt creation, agentic pipeline work, project roadmap, meta-prompts, research to implement workflow.
linkedin-sales-navigator-alt-skill
Build targeted prospect lists by analyzing LinkedIn profiles, extracting job titles, companies, locations, and recent activity. Identifies decision-makers, tracks job changes for warm outreach, and enriches contact data. Use when users need to find prospects, build lead lists, or track decision-maker movements.
Didn't find tool you were looking for?