Migration Safety Gate

    by Zé Francisco Rocha

    1

    Catches the migration that silently drops your data or locks a production table.

    $5.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Migration Safety Gate

    Example session with this skill installed

    Review this PostgreSQL 14 migration for a table with 50M rows: ALTER TABLE orders ADD COLUMN status VARCHAR(255) DEFAULT 'pending' NOT NULL; ALTER TABLE orders ADD COLUMN metadata JSON;

    • Read your context and instructions
    • Compiled the migration safety gate

    The migration was analyzed for PostgreSQL 14. Adding a column with a constant default is metadata-only in this version, but the second operation carries minor risks.

    Verdict — GO WITH CONDITIONS

    Findings

    #StatementClassSeverityImpactFix
    1ADD COLUMN statusLockingNoteMinimal on PG 11+ due to fast default.Ensure no long-running transactions exist.
    2ADD COLUMN metadataLockingWarningACCESS EXCLUSIVE lock could block the queue.Use a lock_timeout for the session.
    3Combined opsDeployWarningTotal lock time increases with multiple DDLs.Split into individual transactions.

    Rewritten Migration

    -- Step 1: Set a short lock timeout to prevent queue pile-up
    SET lock_timeout = '2s';
    
    -- Step 2: Add columns (Fast in PG 14)
    ALTER TABLE orders 
      ADD COLUMN status VARCHAR(255) DEFAULT 'pending' NOT NULL,
      ADD COLUMN metadata JSON;
    

    Pre-flight Checklist

    • Verify Table Size: SELECT pg_size_pretty(pg_total_relation_size('orders'));
    • Check Active Locks: Run SELECT pid, state, query FROM pg_stat_activity WHERE wait_event_type = 'Lock'; before running.
    • Transaction Check: Ensure no long-running analytical queries are holding ACCESS SHARE locks on the orders table.

    Next steps

    • Run the row count and lock check queries provided in the checklist.
    • Apply the migration during a period of lower traffic to minimize the impact of the brief ACCESS EXCLUSIVE lock.

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

    About this skill

    The failure this catches

    Most migrations that cause an outage look completely ordinary in review. The damage comes from four places, and a reviewer reading the file cannot see three of them.

    The four checks

    • Data destruction. Including the one nobody expects: many ORMs emit DROP COLUMN + ADD COLUMN when they cannot express an in-place alter. The schema is correct afterwards and every row is null.
    • Locking and downtime. Which lock each statement takes, on your engine and version - PostgreSQL 11 and 14 differ materially, MySQL differs again. Including the lock-queue trap: a blocked ALTER TABLE waiting behind a long read blocks every subsequent query on that table, reads included. A 30-second migration becomes a total outage.
    • Backward compatibility. Only matters if old and new code run at once during deploy - so it asks, rather than assuming.
    • Reversibility. And it says plainly whether your rollback restores the data or only the schema.

    What you get back

    A GO / GO WITH CONDITIONS / NO-GO verdict on the first line, a severity-ranked findings table, and - the part you actually want - the rewritten migration as runnable SQL, split into the separate deploys it really requires. Plus a pre-flight checklist: the exact queries to run for row counts and long-running transactions, and the lock_timeout to set.

    Rules it holds to

    It never approves a migration whose emitted SQL it has not seen. It never softens a blocker to a warning because the fix is inconvenient. Where the engine version is unknown it reports against the most restrictive plausible version and tells you which it assumed.

    Requires emitted SQL for ORM migrations. Does not analyze query performance or index efficiency. User must provide table row counts and engine versions for accurate locking analysis.

    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 migration scripts to detect hidden risks like implicit data loss from ORM 'drop and add' commands, table-locking bottlenecks, and version-specific engine behaviors that could lead to production downtime.

    This skill supports PostgreSQL and MySQL, including version-specific nuances (e.g., changes between Postgres 11 and 14) to ensure locking behavior is accurately predicted for your specific environment.

    Beyond just flagging risks, the skill provides a rewritten, runnable SQL script split into safe deployment phases and a pre-flight checklist with specific 'lock_timeout' settings and diagnostic queries.

    The Safety Gate can be integrated into most AI-driven code review agents or CI/CD workflows that allow for a SQL analysis step before code is merged or deployed.

    Yes, the skill explicitly checks for backward compatibility and flags migrations that would break existing application code during blue-green or rolling deployments.

    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.