# SQL Query & Migration Safety Surgeon

> 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.

SQL Query & Migration Safety Surgeon is a paid AI agent skill on Agensi by Badung, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $3.99 (one-time purchase)
- Creator: [Badung](https://www.agensi.io/creators/badung)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Version: 1.0
- Last updated: 2026-12-03
- Security: scan passed (2026-12-03); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/sql-query-migration-safety-surgeon
- Tags: database, code-review, sql, postgresql, mysql, prisma, drizzle

## 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: "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: "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: "Review this SQL migration script for data loss risks or production locking issues."

## 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**
1. Share a snippet of database code, a migration file, or an ORM function with your AI agent.
2. The skill audits the code for five major risks, including data loss and slow performance.
3. You receive a list of findings marked by how urgent they are to fix.
4. 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.

## Requires

No database connection needed: paste the SQL, EXPLAIN output, ORM snippet or migration file, or let your agent read the file in your project.

## Known limitations

You must run the suggested verification commands yourself to confirm results on your specific data volume.

## Technical details

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 this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the SQL Query & Migration Safety Surgeon skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What kinds of database problems can this skill find?

This skill checks your database code for mistakes that cause slow performance, site crashes, or permanent data loss. It looks for issues like missing indexes that slow down searches and unsafe updates that can lock your site during high traffic.

### Do I need to install any special database software to use this?

You only need to share your database files or code snippets with your AI agent. It works with standard SQL files and modern tools like Prisma, Drizzle, TypeORM, and SQLAlchemy, as well as database engines like PostgreSQL, MySQL, and SQLite.

### What do I actually get after the skill finishes its audit?

You receive a safety report that labels risks by how urgent they are to fix. The report includes specific code patches to resolve the issues and a step by step plan to test and deploy the changes safely.

### Are there any safety steps I need to take myself?

The skill assumes you have a way to test its suggestions on your own computer first. It requires you to verify the code against your specific database version and row counts before applying them to a live site.

### How do I get my AI agent to start the database audit?

Simply ask your AI agent to review a specific database file, a migration folder, or a snippet of SQL code. If you do not name a file, the skill can search your project for database related files to audit.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
