/claude-crown:sql-kingfrom Claude Crown
Foundation skill for everything involving a cloud database (Postgres / Supabase) in a TypeScript app. Teaches clean query writing, table and index design, migrations instead of dashboard clicks, performance analysis with EXPLAIN, and the mandatory "definition of done" checklist for every new table. Also the entry point (router) to the sibling skills sql-security (keys, roles, privileges, rate limiting) and rls-security (row level security). ALWAYS use this skill when: a table, column, view or migration is created or changed; a SELECT/INSERT/UPDATE/DELETE query or a Supabase client call is written; the user mentions "database", "DB", "SQL", "query", "table", "schema", "migration", "Supabase", "Postgres", "slow", "index" or "data model"; data is read or written from the frontend; data modelling is being discussed. Also trigger when database work is only implicit — for example a new feature that stores anything.
Ships in Claude Crown. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
This skill is the base layer for database work in a TypeScript + Postgres/Supabase app. The goal is queries that are correct, fast and safe — in that order.
The sentence that holds the whole skill set together:
A table is finished when grants, policies and a test exist. Not when
CREATE TABLEran without an error.
Answer these first. They prevent most problems later:
anon / authenticated) or a server
(role service_role, which bypasses RLS)? This decides the security layer.LIMIT
and pagination are missing.| Situation | Skill |
|---|---|
| Writing a query, designing a schema, adding an index, writing a migration | sql-king (this one) |
Keys, .env, roles, GRANT/REVOKE, who may DROP, rate limiting, injection | sql-security |
Who may see or change which row? Policies, auth.uid(), tenant isolation | rls-security |
A new table needs all three. Order: schema (sql-king) → privileges (sql-security) → policies (rls-security).
Postgres checks two separate things on every access:
Request
│
▼
[1] GRANT → May this role perform this operation on this table at all?
│ Missing grant: error 42501 "permission denied"
▼
[2] RLS POLICY → Which ROWS may it touch while doing so?
│ No matching policy: empty result, NO error
▼
Result
This gives the single most useful debugging rule in the whole skill set:
Protecting a table with policies alone is not enough. As long as the grant for anon is still
in place, a write path exists. Always set both.
Sources: Supabase — Understanding RLS, Postgres — Privileges
Work through this for every new table. No item is optional.
[ ] 1. Table created in a migration file (not clicked together in the dashboard)
[ ] 2. Primary key present (uuid default gen_random_uuid())
[ ] 3. Foreign keys declared with references ... on delete <rule>
[ ] 4. created_at / updated_at timestamptz default now()
[ ] 5. NOT NULL wherever it makes sense, CHECK constraints for value ranges
[ ] 6. Index on every column used for filtering or joining (including policy columns!)
[ ] 7. RLS enabled: alter table ... enable row level security → rls-security
[ ] 8. Grants explicitly set and revoked for anon + authenticated → sql-security
[ ] 9. One policy each for select / insert / update / delete → rls-security
[ ] 10. Test written: another user does NOT see the row → rls-security
Item 10 matters most. Without a negative test, the protection is only a claim.
select * against the database// bad — fetches every column, breaks types on any schema change
const { data } = await supabase.from('orders').select('*')
// good — only what is needed, plus a limit
const { data } = await supabase
.from('orders')
.select('id, title, status, customer_id, created_at')
.eq('status', 'open')
.order('created_at', { ascending: false })
.limit(50)
Fewer columns means fewer bytes on the wire and a real chance of an index-only scan.
// bad — loads 40,000 rows into the browser and throws 39,950 away
const all = await supabase.from('orders').select('*')
const open = all.data.filter(o => o.status === 'open')
// good
const open = await supabase.from('orders').select('id, title').eq('status', 'open')
This is not only slow, it is a data leak: everything the client loads is readable in the network tab, even if the UI filters it out afterwards.
// bad — 1 query for orders plus 1 per order = 51 round trips
const orders = await supabase.from('orders').select('id, customer_id').limit(50)
for (const o of orders.data) {
const c = await supabase.from('customers').select('name').eq('id', o.customer_id).single()
}
// good — one round trip with an embedded join
const { data } = await supabase
.from('orders')
.select('id, title, customers ( id, name )')
.limit(50)
Source: Supabase — Joins and nesting
.order('created_at', { ascending: false })
.order('id', { ascending: false }) // tiebreaker, otherwise rows jump between pages
.range(0, 49)
On large tables, keyset pagination (where created_at < :lastValue) is much faster than
offset, because Postgres still walks 10,000 rows to satisfy offset 10000.
create index on orders (customer_id, created_at desc)).create index concurrently, otherwise the table is locked for writes.Details, index types (btree/gin/partial) and examples: references/schema-and-indexes.md
explain (analyze, buffers)
select id, title from orders where customer_id = '…' order by created_at desc limit 20;
What to look for:
Seq Scan on a large table → an index is missingrows=1000 vs. actual rows=250000 → stale statistics, run analyze <table>Source: Postgres — Using EXPLAIN
Ready-made diagnostic queries (slowest queries, unused indexes, unindexed foreign keys) are in
references/query-patterns.md.
Before judging an existing project, scan it — then verify each lead at the element:
python scripts/sql_scan.py <project-root> [--sql-dirs supabase/migrations] [--src-dirs src app] [--json] [--fail-on HIGH]
Stdlib only. Migrations: tables without enable row level security, RLS tables missing a
policy per operation, update/insert policies without with check, for all policies,
unwrapped auth.uid(), security definer without set search_path, foreign keys without an
index, tables without an explicit revoke … from anon. Client code: secret keys on the client
path, select('*'), query chains without a limit, .from(<variable>), .or() strings built
from input. Prints the counts per category plus every hit with file and line. The remaining
proof is a run of supabase db lint and the negative tests — the scanner reads files, it does
not see grants that live only in the database.
Every schema change belongs in the repository as a file. Changes clicked in the dashboard do not exist locally, cannot be reviewed and cannot be rolled back.
supabase migration new orders_status_index # creates a timestamped file
# write the SQL into that file, then:
supabase db reset # rebuild locally from scratch and verify
supabase db push # only then push to remote
Rules, ordering inside the file and rollback strategy: references/migrations.md
Source: Supabase — Local development
scripts/sql_scan.py. Check whether a table already holds similar data.explain analyze on the new queries, plus the RLS negative tests
from rls-security.references/query-patterns.md — query building blocks, joins, aggregation, upsert,
transactions, diagnostics. Read when writing or optimising a concrete query.references/schema-and-indexes.md — data types, constraints, naming, index types.
Read when designing or changing a table.references/migrations.md — migration workflow, safe DDL changes, rollback.
Read when writing a migration.references/sources.md — all official documentation links, grouped by topic.scripts/sql_scan.py — static scan of migrations and client code (see Quick start). Run it
first on any existing project; fixtures under evals/fixtures/ show what it flags.At the end of every database task, check:
select *, a missing limit and client-side filtering?evals/evals.json (opens in a new tab)evals/fixtures/bad/src/lib/notes.ts (opens in a new tab)evals/fixtures/bad/supabase/migrations/20260101000000_notes.sql (opens in a new tab)evals/fixtures/good/src/lib/notes.ts (opens in a new tab)evals/fixtures/good/supabase/migrations/20260101000000_notes.sql (opens in a new tab)references/migrations.md (opens in a new tab)references/query-patterns.md (opens in a new tab)references/schema-and-indexes.md (opens in a new tab)references/sources.md (opens in a new tab)scripts/sql_scan.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub 2fwn2rnh7v-pixel/claude-crown --plugin claude-crown12 skills in this plugin
/api-guardAudits and hardens API usage in TypeScript web apps: rate limiting and quotas, API keys and paid calls in the backend instead of the frontend, protection against cost explosions, and lowering API consumption for the same result (caching, batching, debouncing, payload trimming, model routing). Script-backed quick scan of existing code. Use ALWAYS when: an API call, fetch(), axios or an SDK client is written; an endpoint, route, Server Action, server function or Edge Function is created; API keys, secrets, tokens, .env, NEXT_PUBLIC_/VITE_ variables appear; an external service is connected (LLM, weather, maps, payment, Supabase, Cloudflare); the user says "Rate Limit", "Quota", "Kosten", "teuer", "Rechnung", "Verbrauch", "zu viele Requests", "429", "API-Key", "Missbrauch", "cost", "usage", "throttle", "caching" or "prüf mal meine API-Nutzung". Also trigger implicitly — when the frontend calls an external service directly, or a search, autocomplete or polling loop is built without anyone mentioning cost.
/java-pioneerExpert playbook for writing production-grade Java (21/25 LTS) backends with Spring Boot 4 and connecting them to web frontends (React, Angular, Vue, plain TypeScript) with maximum safety and performance. Use this skill whenever the user writes, reviews, refactors, debugs, or designs Java code — Spring Boot services, REST APIs, JPA/Hibernate persistence, Spring Security, login/sessions/OAuth2/JWT, CORS or CSRF errors, OpenAPI contracts, TypeScript clients for a Java API, JVM or database performance, Maven/Gradle builds, or Java tests with JUnit/Mockito/Testcontainers — even if the user never says "best practices". Also use it for migrations from older Java versions or Spring Boot 2/3.Other plugins' skills for the same job