Works with the AI Agents you already use

    Database Query & Migration Optimizer

    by Via mae Sarol

    1

    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

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Database Query & Migration Optimizer

    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

    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

    FeatureCurrent StateOptimized StateImpact
    Query PatternN+1 (1 + N + M queries)Eager Load (3 queries total)High
    Index StrategySequential ScanIndex Scan (Composite)Medium
    Locking ImpactNone (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

    1. Run the migration using a tool that supports non-transactional DDL (e.g., Prisma's $executeRawUnsafe or direct CLI).
    2. Verify the index is valid using \d comments in psql after completion.
    3. Monitor for any temporary CPU spikes during the concurrent index build.

    Connects securely to your tools. The creator never sees your data.

    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, and ORDER BY clause cardinality.
    • Rewrites expensive subqueries into Common Table Expressions (CTEs) or window functions.
    • Replaces slow OFFSET/LIMIT scanning 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 use

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

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

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

    Frequently Asked Questions

    The skill analyzes ORM code or raw SQL to identify inefficiencies like N+1 loops and slow scans, then generates optimized queries and migration files tailored to your specific database engine.

    It supports PostgreSQL, MySQL, MariaDB, and SQLite, along with major ORMs like Prisma, Drizzle, SQLAlchemy, Django, and TypeORM.

    The skill evaluates migrations based on engine-specific locking behavior, recommending 'online' strategies like PostgreSQL's CONCURRENTLY index creation to prevent table locks during high-traffic periods.

    You will receive the full AI agent skill definition, including the specialized logic for query refactoring, indexing architecture, and database-specific locking rules.

    For the most accurate locking impact classification and syntax generation, you should provide the specific database engine name and version number (e.g., PostgreSQL 15 or MySQL 8.0).

    Simply import the skill into your preferred AI agent host; it works by reviewing your schema files, ORM snippets, or SQL logs to provide actionable refactoring advice.

    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.