Works with the AI Agents you already use

    Safe Migration & Slow-Query Fixer

    by Maulana Ruhaedi Putra

    1

    Gate Laravel migrations for production safety (MySQL/PostgreSQL locking, expand-contract, BLOCK/REVIEW/PASS) and find/fix N+1 and slow queries with measured before/after numbers.

    Free

    Security scanned
    Safe Migration & Slow-Query Fixer

    Safe Migration & Slow-Query Fixer

    Example session with this skill installed

    Review the pending migration 2024_10_01_add_index_to_orders_table.php for a PostgreSQL production database with 50M rows.

    • Read your context and instructions
    • Compiled the safe migration

    I have audited the migration against the safety gate for a PostgreSQL environment with 50M rows.

    Migration Gate Report

    Rule IDResultEvidenceTable size usedOwner
    M-03BLOCKCREATE INDEX detected on 50M rows without CONCURRENTLY50,000,000Agent
    M-07BLOCKwithinTransaction is true, but CONCURRENTLY requires it to be false50,000,000Agent
    M-08PASSSET lock_timeout = '2s' found at top of migration50,000,000Agent
    M-06PASSdown() correctly drops the index50,000,000Agent

    Overall: NO-GO

    Unresolved blockers:

    • M-03: Plain index creation on a large table will lock the table for writes. Use ->online() or raw CREATE INDEX CONCURRENTLY.
    • M-07: PostgreSQL cannot create indexes concurrently inside a transaction. Set public $withinTransaction = false; in the migration class.

    Next steps

    1. Update the migration to use ->online() and set $withinTransaction = false.
    2. Run php artisan migrate --pretend again to verify the generated SQL includes CONCURRENTLY.
    3. Re-run this gate for a final PASS.

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

    About this skill

    Database migrations on production tables often cause downtime through locks, while N+1 queries and missing indexes degrade performance as data grows. This skill provides a rigorous safety gate for Laravel migrations and a measurement-first workflow for fixing slow queries.

    What it does

    • Migration gating classifies schema changes as PASS, REVIEW, or BLOCK based on production safety rules for MySQL and PostgreSQL.
    • Lock prevention enforces fail-fast lock timeouts and engine-specific safe operations like CONCURRENTLY or ALGORITHM=INPLACE.
    • N+1 detection identifies redundant queries using Model::preventLazyLoading and query log analysis.
    • Performance measurement requires before/after benchmarks for every fix, including query counts and execution time in milliseconds.
    • Index optimization analyzes EXPLAIN plans to recommend composite, covering, or partial indexes based on real query shapes.

    How it works

    1. Engine detection identifies the database type and version from config/database.php to branch rule logic.
    2. Pre-flight audit records table sizes and runs migrate --pretend to inspect the raw SQL before execution.
    3. Safety validation checks the migration against a matrix of destructive operations and locking behaviors.
    4. Performance fix applies eager loading or index changes and verifies the result with at least three benchmark runs.

    Frameworks & tools

    This skill is built for Laravel applications using MySQL, MariaDB, or PostgreSQL. It utilizes Eloquent, Laravel Telescope, and the standard database migration system.

    Why this beats prompting it yourself

    Generic prompts often miss engine-specific locking nuances like how PostgreSQL handles foreign keys versus MySQL. This skill enforces a strict "no numbers, no fix" policy that prevents developers from shipping unverified optimizations or hiding N+1 issues behind a cache.

    Use cases

    • Reviewing a migration that adds a column to a table with millions of rows.
    • Fixing an API endpoint that gets slower as the number of related records grows.
    • Reverting a migration that lacks a proper down() method or contains destructive SQL.
    • Optimizing complex queries by analyzing and improving the EXPLAIN execution plan.

    Known limitations

    Does not support live production profiling or load testing. Measurements on local environments may differ from production due to hardware and data volume variance.

    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

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 5 days ago

    • Free with an Agensi account

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Network Access
    Listed5 days ago

    What's inside

    Frequently Asked Questions

    This skill acts as an automated safety gate that analyzes Laravel migrations for potential locking issues and provides a measurement-driven workflow to eliminate N+1 queries and slow database execution. It ensures that schema changes won't lock large tables and that performance improvements are verified with actual benchmark data.

    The skill is purpose-built for Laravel applications running on MySQL, MariaDB, or PostgreSQL. It integrates directly with Eloquent and Laravel's migration system, leveraging engine-specific rules for each database type to handle locking behaviors correctly.

    Unlike a standard LLM prompt, this skill understands the nuanced differences between database engines, such as how PostgreSQL handles CONCURRENTLY indexes versus MySQL's ALGORITHM=INPLACE. It also enforces a 'measurement-first' policy, refusing to finalize a fix unless it can prove a performance gain through before-and-after benchmarks.

    You will receive the AI agent skill package including the safety rule matrix, the benchmark workflow logic, and the pre-flight audit protocols. It includes everything needed to integrate the agent into your CI/CD pipeline or local development environment.

    While the skill provides highly accurate safety classifications, it is intended to support and inform your engineering team rather than replace them. It marks migrations as PASS, REVIEW, or BLOCK, allowing your developers to make the final decision on high-risk operations.

    The skill performs a pre-flight audit using 'migrate --pretend' to inspect raw SQL and checks table metadata to predict locking behavior. However, because it operates in your development or staging environment, it cannot account for real-time production traffic spikes or unique server hardware configurations.

    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.

    Free