Migration Guard

    1

    Analyze database migrations for locking risks, downtime, and data loss before they hit production.

    $19

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    Migration Guard

    Example session with this skill installed

    I just added a migration to add a NOT NULL constraint to the users table in my Rails app. Is this safe to deploy to our production Postgres DB?

    • Read your context and instructions
    • Compiled the migration guard

    I have reviewed 20231027120000_add_not_null_to_users_email.rb. Adding a NOT NULL constraint to an existing column in PostgreSQL requires a full table scan while holding an SHARE UPDATE EXCLUSIVE lock, which will block writes on a large table.

    Migration Risk Report

    OperationSeverityRisk TypeSQL Equivalent
    change_column_nullHIGHTable Scan / Lock ContentionALTER TABLE "users" ALTER COLUMN "email" SET NOT NULL;

    Analysis

    PostgreSQL must verify that no null values exist before applying the constraint. On a large users table, this scan can take significant time. Because this migration runs in a transaction, it holds the lock for the duration of the scan, potentially causing a connection pile-up.

    Safe Rewrite (Expand/Contract Pattern)

    To deploy this safely, you should split this into three steps across two deployments.

    Step 1: Add a Check Constraint (Invalid)
    This adds the constraint without validating existing rows, avoiding the long lock.

    class AddEmailNotNullConstraint < ActiveRecord::Migration[7.0]
      def change
        add_check_constraint :users, "email IS NOT NULL", name: "email_is_not_null", validate: false
      end
    end
    

    Step 2: Validate the Constraint
    Run this in a separate migration. The scan is performed, but it does not block reads or writes.

    class ValidateEmailNotNullConstraint < ActiveRecord::Migration[7.0]
      def change
        validate_check_constraint :users, name: "email_is_not_null"
      end
    end
    

    Step 3: Finalize (Optional)
    Once validated, you can safely set the actual NOT NULL column property as it is now a metadata-only change.

    Next steps

    1. Replace the current migration with the "Step 1" code block.
    2. Verify if there are any existing NULL values in the email column before running Step 2.
    3. Apply a statement_timeout to your migration runner for added safety.

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

    About this skill

    The problem

    Schema migrations are a leading cause of production outages. A single ALTER TABLE on a hot table can block all incoming queries, exhaust connection pools, and take down an entire application in seconds.

    What it does

    • Analyzes migration files for ACCESS EXCLUSIVE locks and head-of-line blocking risks.
    • Detects operations that force full table rewrites or long-running scans on large datasets.
    • Identifies breaking changes where old application code will fail after the schema lands.
    • Flags destructive operations like DROP COLUMN or TRUNCATE that lack a rollback path.
    • Generates per-operation risk reports with severity levels from Low to Critical.

    Frameworks & tools

    Supports PostgreSQL and MySQL/MariaDB. Compatible with ActiveRecord (Rails), Django, Alembic (SQLAlchemy), Prisma, TypeORM, Sequelize, Knex, Ecto, Flyway, and Liquibase.

    Why this beats prompting it yourself

    Generic LLMs often miss the nuanced locking behavior differences between database engines or specific ORM quirks. This skill uses dedicated reference sets for Postgres and MySQL lock matrices to ensure rewrites actually work in production environments.

    Use cases

    • Reviewing Pull Requests that introduce database schema changes.
    • Refactoring blocking migrations into safe expand-contract patterns.
    • Planning batch backfills for multi-million row tables.
    • Auditing legacy migrations for missing down/rollback paths.

    Known limitations

    Cannot access live database statistics like real table sizes or current lock contention. Row-level security and complex triggers require manual review.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    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

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scanned

    Verified clean 1 month ago

    • Passed all security checks, Safe to install

    Requires

    Python

    Listed1 month ago

    What's inside

    Frequently Asked Questions