ProSkillsLibraryFreePassScan
Data & SQL

Data & SQL · agent skill

SQL Reviewer

Catches the NULL, fan-out and lock bugs.

What it does

Loads when it is needed

Your agent loads it when a diff contains SQL, an ORM query or a migration. It carries 5 rules and reads a profile.md with your details before it starts, so the output matches your brand and project.

Same prompt, with and without

Review revenue report PR

Prompt · Can you review the SQL in this PR before I merge it? It adds a monthly revenue report, an index on orders, and a status filter endpoint.

# reports/revenue_by_region.sql
1 SELECT c.region, SUM(o.total_cents) AS revenue_cents, COUNT(*) AS orders
2 FROM orders o
3 JOIN order_items i ON i.order_id = o.id
4 LEFT JOIN customers c ON c.id = o.customer_id
5 WHERE c.region <> 'internal'
6   AND date(o.created_at) BETWEEN '2025-03-01' AND '2025-03-31'
7 GROUP BY c.region;

# orders/migrations/0042_orders_index.py
12 migrations.RunSQL("CREATE INDEX idx_orders_cust_created ON orders (customer_id, created_at);")

# api/views.py
41 cur.execute(f"SELECT id, total_cents FROM orders WHERE status = '{request.GET['status']}' ORDER BY created_at DESC")

Profile used: Postgres 15, Django ORM, 12M-row orders table; snake_case, migrations run in a transaction by default

Without the skill
Please don't merge as is. Issues, most serious first: 1. api/views.py:41 is SQL injection. The status value goes straight into an f-string. Use cur.execute("... WHERE status = %s ORDER BY created_at DESC", [status]) and ideally validate against the allowed statuses. Add a LIMIT too. 2. revenue_by_region.sql joins order_items, which multiplies each order by its item count. SUM(o.total_cents) and COUNT(*) are inflated. You don't use any item columns, so drop that join (or pre-aggregate items). 3. LEFT JOIN customers plus WHERE c.region <> 'internal' silently becomes an inner join. Orders with no customer or a NULL region vanish, since NULL <> 'x' is not true. Use c.region IS DISTINCT FROM 'internal' if you want them included, or make the intent explicit. 4. date(o.created_at) BETWEEN ... can't use an index and depends on the session timezone. Use o.created_at >= '2025-03-01' AND o.created_at < '2025-04-01' (with an explicit time zone). 5. The migration runs CREATE INDEX inside a transaction, which blocks writes on a 12M-row table while it builds. Use AddIndexConcurrently from django.contrib.postgres.operations with atomic = False. 6. The (customer_id, created_at) index doesn't help the status endpoint. That query needs something like (status, created_at DESC). Also check that the report itself benefits from this index.
With the skill
SQL review: monthly revenue report Database: Postgres 15 Statements reviewed: 3 Verdict: Request changes (3 blockers, 2 should-fix) [blocker] reports/revenue_by_region.sql:1 SUM(o.total_cents) runs after JOIN order_items, so a 3-item order adds its total 3 times and COUNT(*) counts items, not orders. Fix: drop the order_items join (nothing selected from it), or pre-aggregate items per order first. [blocker] api/views.py:41 User input is concatenated into the SQL: status=' OR '1'='1 returns every order. Also no LIMIT on a list endpoint. Fix: cur.execute("... WHERE status = %s ORDER BY created_at DESC, id DESC LIMIT 50", [status]). [blocker] orders/migrations/0042_orders_index.py:12 CREATE INDEX without CONCURRENTLY holds a SHARE lock for the whole build; on 12M rows that blocks every order write, and it runs inside Django's migration transaction. Fix: atomic = False and CREATE INDEX CONCURRENTLY (or AddIndexConcurrently). Check indisvalid after. [should-fix] reports/revenue_by_region.sql:5 The WHERE on c.region turns the LEFT JOIN into an inner join: NULL <> 'internal' is NULL, so orders with no customer or region vanish from revenue. Fix: c.region IS DISTINCT FROM 'internal'. [should-fix] reports/revenue_by_region.sql:6 date(o.created_at) uses the session time zone and cannot use an index on created_at. Fix: o.created_at >= '2025-03-01' AND o.created_at < '2025-04-01', with the zone stated. Not run: nothing executed against a database.

Both answers from the same model (Claude sonnet), 2026-10-16. The one without the skill was written in a separate session that never saw it. Shortened where marked with …

Install

One command, in your project

It detects your agent; add --agent all for every agent.

npx proskills-cli add sql-reviewer --order <order id from your receipt>

Or copy the skill folder (the one holding SKILL.md) into the directory your agent reads, then restart it or start a new session.

AgentThis projectEvery project
Claude Code.claude/skills/~/.claude/skills/
Cursor.agents/skills/ (or .cursor/skills/)~/.cursor/skills/
Codex.agents/skills/~/.agents/skills/
Gemini CLI.agents/skills/ (or .gemini/skills/)~/.gemini/skills/

Changelog

What changed

  • v1.0.0 · 2026-10-16
    • First versioned release: Catches the NULL, fan-out and lock bugs.
    • Scanned 100/100 before release.

Keep it current with npx proskills-cli update; your profile.md is never touched. Everyone who bought it gets the update free and an email when it lands.

Same collection

More from Data & SQL

The scan checks spec compliance, token cost, clarity and security patterns. A clean scan is not a guarantee: static scanners can be evaded. Scan any skill yourself.