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.
What this skill does
<objective>
Clean and format SQL migrations for direct paste into Supabase SQL Editor. Ensures idempotency, proper RLS policies (especially service role patterns), standardized formatting, and dependency documentation.
</objective>
<quick_start>
**Clean any SQL migration:**
1. Fix typos (`- ` → `-- ` for comments)
2. Add idempotency (`IF NOT EXISTS`, `DROP ... IF EXISTS`)
3. Fix RLS policies (service role uses `TO service_role`, not JWT checks)
4. Remove dead code (unused enums)
5. Standardize casing (`NOW()`, `TIMESTAMPTZ`)
6. Add dependencies comment at end
```sql
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 EXISTS` before `CREATE`
- 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:
1. **Fix typos** - Common: `- ` instead of `-- ` on comment lines
2. **Add idempotency** - `IF NOT EXISTS` on indexes, `DROP ... IF EXISTS` before policies/triggers
3. **Remove dead code** - Enums created but never used (TEXT + CHECK often preferred)
4. **Fix RLS policies** - Service role must use `TO service_role`, not JWT checks
5. **Standardize casing** - `NOW()` not `now()`, `TIMESTAMPTZ` not `timestamptz`
6. **Remove clutter** - Verbose RAISE NOTICE blocks, redundant comments, file path headers
7. **Validate dependencies** - List required tables at end
## Output Format
```sql
-- ============================================
-- 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
```sql
-- 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
```sql
-- Always drop before create
DROP POLICY IF EXISTS "Policy name" ON table_name;
CREATE POLICY "Policy name" ON table_name ...
```
### Idempotent Triggers
```sql
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:
```sql
-- 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:
```sql
-- Dependencies: businesses, call_logs, subscription_plans
-- Requires function: update_updated_at_column()
```
## Reference Files
- `reference/rls-patterns.md` - Common RLS policy patterns for Supabase
- `reference/function-patterns.md` - Trigger functions, atomic operations
## Emit Outcome Sidecar
As the final step, write to `~/.claude/skill-analytics/last-outcome-supabase-sql.json`:
```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.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.