- Home
- Skills
- Data & Databases
- SQL Query & Migration Safety Surgeon
Works with the AI Agents you already use
SQL Query & Migration Safety Surgeon
by Badung
Audit SQL queries, EXPLAIN plans, ORM calls and migrations for missing indexes, N+1 loops, table locks, data loss and injection risk, with minimal patches and safe rollout steps.
$3.99
What it does
- Identifies missing indexes that cause slow searches and high server costs
- Flags unsafe migration steps that could lock your database or cause data loss
- Detects N+1 loops where your app makes too many individual requests to the database
- Spots security risks like SQL injection where user input could corrupt your data
- Provides minimal code patches to rewrite slow queries into fast ones
- Suggests exact commands to verify performance improvements before you go live
Who it's for
Startup founders building with AI assistants
Stop database crashes before they happen by checking your queries and migrations for common traps.
Try asking: “Check if these new database tables will slow down the site when we have 10,000 users.”
Freelance web developers using ORMs like Prisma or Drizzle
Find hidden performance bottlenecks and N+1 loops in your database code automatically.
Try asking: “Scan my prisma/schema.prisma and recent migration files for any unsafe locks or missing indexes.”
Product managers overseeing technical releases
Ensure that upcoming database changes won't lock up the app or lose customer data.
Try asking: “Review this SQL migration script for data loss risks or production locking issues.”
SQL Query & Migration Safety Surgeon
Example session with this skill installed
Review this PostgreSQL migration and query before we deploy:
CREATE INDEX idx_orders_status ON orders(created_at, status);
ALTER TABLE orders ADD COLUMN coupon_code VARCHAR(32) NOT NULL;
And in TypeScript
const users = await db.query("SELECT * FROM users WHERE active = true");
for (const u of users.rows) {
u.orders = await db.query(`SELECT * FROM orders WHERE status = 'paid' AND user_id = ${u.id} ORDER BY created_at DESC LIMIT 5`);
}
- Read your context and instructions
- Compiled the sql query
Found 4 issues across migration safety, indexing, N+1 queries, and SQL injection.
- [BLOCKER]
INJECTION_OR_TX_BLOAT(request:7):user_id = ${u.id}interpolates user input directly into SQL. - [BLOCKER]
UNSAFE_MIGRATION_LOCK(request:1-2):CREATE INDEXwithoutCONCURRENTLYblocks writes onorders, andADD COLUMN ... NOT NULLwithout a default or backfill fails ifordersalready has rows. - [HIGH]
ORM_N_PLUS_ONE(request:5-8): Running oneordersquery per active user creates N+1 round trips. - [HIGH]
SEQ_SCAN_MISSING_INDEX(request:1,7):idx_orders_status(created_at, status)puts the range/sort column first and omitsuser_id; the query filters by(user_id, status)then sorts bycreated_at.
Minimal Patch
-- Step 1: Safe concurrent index matching (equality -> sort)
SET lock_timeout = '2s';
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_orders_user_status_created
ON orders (user_id, status, created_at DESC);
-- Step 2: Expand-contract nullable column first, then backfill, then NOT NULL
ALTER TABLE orders ADD COLUMN IF NOT EXISTS coupon_code VARCHAR(32);
// Single parameterized lateral/window query instead of N+1 loop
const { rows } = await db.query(
`SELECT u.id, o.*
FROM users u
LEFT JOIN LATERAL (
SELECT id, status, created_at, coupon_code
FROM orders
WHERE user_id = u.id AND status = $1
ORDER BY created_at DESC
LIMIT 5
) o ON true
WHERE u.active = true`,
['paid']
);
Verification: Pending local run — Run EXPLAIN (ANALYZE, BUFFERS) on the LATERAL query in staging to confirm Index Scan on idx_orders_user_status_created, and test the migration on a snapshot with existing orders rows.
Assumptions: PostgreSQL 14+, orders table already contains rows in production.
Connects securely to your tools. The creator never sees your data.
About this skill
If your app slows down or crashes during a database update, it is usually because of a hidden mistake in how the data is handled. This skill acts as a safety expert for your AI agent, specifically for database tasks. It looks for common traps like missing indexes that make searches slow, or "locks" that freeze your site while a new column is being added.
Whether you are using raw SQL or modern tools like Prisma and Drizzle, this skill scans your code to find risks. It doesn't just point out problems, it gives you the exact code to fix them and the steps to test them safely on your own computer first.
How it works
- Share a snippet of database code, a migration file, or an ORM function with your AI agent.
- The skill audits the code for five major risks, including data loss and slow performance.
- You receive a list of findings marked by how urgent they are to fix.
- You get a specific code patch and a plan to verify the fix works.
What you get: A safety report with fixed code and a step-by-step plan to deploy database changes without downtime.
You must run the suggested verification commands yourself to confirm results on your specific data volume.
Built for Claude Code and Codex environments. Uses Read, Grep, and Glob tools to inspect SQL, ORM (Prisma, Drizzle, SQLAlchemy, etc.), and migration files. Performs static analysis across five axes: SEQ_SCAN_MISSING_INDEX, ORM_N_PLUS_ONE, UNSAFE_MIGRATION_LOCK, DATA_LOSS_DROP_TRUNCATE, and INJECTION_OR_TX_BLOAT. Output includes severity-weighted findings (BLOCKER/HIGH/NIT) and Citations for specific code lines. Requires manual execution of EXPLAIN ANALYZE for final verification.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 2 days ago
Nothing to install. It runs in your AI agent.
No database connection needed: paste the SQL, EXPLAIN output, ORM snippet or migration file, or let your agent read the file in your project.
Permissions
What's inside
Frequently Asked Questions
New in Data & Databases
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.