- Home
- Skills
- Data & Databases
- Database Query & Migration Optimizer
Works with the AI tools you already use
Database Query & Migration Optimizer
Autonomous DBA skill. Detects N+1 query bottlenecks, missing composite indexes, and generates SQL/ORM migrations classified by real locking impact (Postgres, MySQL, MariaDB, SQLite, Prisma, Drizzle, SQLAlchemy, Django).
$16
Database Query & Migration Optimizer
Example session with this skill installed
Audit this PostgreSQL Prisma query for a news feed. It fetches users, then loops to fetch posts and their comments. Generate a non-blocking index migration for the comments table.
- Read your context and instructions
- Compiled the database query
- Generated the document
I have audited the feed logic. The current implementation triggers an N+1 pattern by fetching comments individually for each post. I have refactored this to use Prisma's include for batch fetching and generated a concurrent migration for the necessary indexes.
Database Optimization Report
| Feature | Current State | Optimized State | Impact |
|---|---|---|---|
| Query Pattern | N+1 (1 + N + M queries) | Eager Load (3 queries total) | High |
| Index Strategy | Sequential Scan | Index Scan (Composite) | Medium |
| Locking Impact | None (Read) | Online (Concurrent Index) | Low |
Refactored Prisma Query
const feed = await prisma.user.findUnique({
where: { id: userId },
include: {
posts: {
include: {
comments: {
orderBy: { createdAt: 'desc' },
take: 20
}
}
}
}
});
PostgreSQL Migration (SQL)
-- UP MIGRATION
-- Classified: ONLINE
-- Impact: No locks on reads or writes. Note: Cannot run inside a transaction block.
CREATE INDEX CONCURRENTLY idx_comments_post_created
ON "Comment" (post_id, created_at DESC);
-- DOWN MIGRATION
-- Classified: ONLINE
DROP INDEX CONCURRENTLY IF EXISTS idx_comments_post_created;
Next steps
- Run the migration using a tool that supports non-transactional DDL (e.g., Prisma's
$executeRawUnsafeor direct CLI). - Verify the index is valid using
\d commentsin psql after completion. - Monitor for any temporary CPU spikes during the concurrent index build.
database-query-migration-optimizer.pdf
PDF · document
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
The problem
Naive ORM queries and unoptimized SQL frequently cause production bottlenecks, N+1 query loops, and table locking during migrations. Developers often guess at index placement or rely on default migration tools that can inadvertently block writes on large production tables.
What it does
- Detects N+1 query patterns in ORM code and provides drop-in refactors using eager loading or batching.
- Architects composite B-Tree indexes based on
WHERE,JOIN, andORDER BYclause cardinality. - Rewrites expensive subqueries into Common Table Expressions (CTEs) or window functions.
- Replaces slow
OFFSET/LIMITscanning with indexed keyset (cursor-based) pagination. - Generates migrations for PostgreSQL, MySQL, and SQLite classified by their real locking impact (online, write-blocking, or downtime-required).
Frameworks & tools
PostgreSQL, MySQL, MariaDB, SQLite, Prisma, Drizzle, SQLAlchemy, Django ORM, TypeORM.
Why this beats prompting it yourself
General LLMs often suggest "zero downtime" migrations that actually trigger metadata locks or write blocks on specific database versions. This skill applies engine-specific rules, such as CREATE INDEX CONCURRENTLY for Postgres and ALGORITHM=INPLACE for MySQL, while validating support for the specific operation to prevent production outages.
Use cases
- Auditing Prisma or Django routes to eliminate nested database loops.
- Optimizing pagination for datasets with millions of rows.
- Refactoring complex 5-table joins into performant CTEs.
- Safe schema migrations for high-traffic tables.
Known limitations
Performance timings are estimates unless a live EXPLAIN ANALYZE output is provided. Requires engine version details for accurate locking classification.
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 23 days ago
- Passed all security checks, Safe to install