Works with the AI Agents you already use

    Spring Migration Safe Rewrite

    by Puneet Swarup

    1

    The whole method is one idea: never change a live table in one step.

    $19

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Spring Migration Safe Rewrite

    Spring Migration Safe Rewrite

    Example session with this skill installed

    Request

    The scan flagged V10 for dropping a column and changing a type. Rewrite it so we
    can deploy on Thursday without an outage and still be able to roll back.
    

    What the agent did

    Ran python scripts/verify.py . on the proposed rewrite, read the findings, then restructured
    the change into three migrations with an undo script.

    • Read your context and instructions
    • Compiled the spring migration safe

    Output (trimmed)

    
    | # | Check | Severity | Where | Problem |
    |---|---|---|---|---|
    | 1 | V1 | high | `V11__bad_rewrite.sql`:1 | column added NOT NULL in the same migration |
    | 2 | V2 | high | `V11__bad_rewrite.sql`:1 | backfill runs as one unbounded statement |
    | 3 | V3 | high | `V11__bad_rewrite.sql`:3 | CREATE INDEX CONCURRENTLY shares a file with other statements |
    | 4 | V4 | high | `V11__bad_rewrite.sql`:7 | destructive step with no rollback script |
    | 5 | V6 | high | `V11__bad_rewrite.sql`:7 | a drop ships in the same migration that adds its replacement |
    
    

    What the agent then said

    Your rewrite is the original migration with the statements reordered, and it keeps two of
    the problems. CONCURRENTLY at line 3 cannot run inside a Flyway transaction on Postgres —
    it fails at deploy time, not at review. And the drop at line 7 still ships with its
    replacement, so Thursday's rollback runs against a schema without legacy_ref.

    Three migrations, three releases:

    V11 — add kyc_status nullable. Nothing reads it. Deploy code that writes both.
    V12 — backfill in batches of 10,000 by id range, from a job you can pause.
    U11 — the undo: drop kyc_status.

    The index goes in its own migration with transactional DDL disabled, or as a step in the
    release runbook. legacy_ref drops in the release after next, once nothing reads it.

    Verified after the change: zero findings on all three files.


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

    About this skill

    A scan tells you the migration will hurt. This produces the migration that does not.

    The whole method is one idea: never change a live table in one step. Add the new thing, backfill it, switch to it, then remove the old thing — one release apart, each step small enough to survive.

    What it does

    Rewrites. For each kind of flagged statement, the actual replacement:

    • A DROP COLUMN becomes deprecate → stop reading → drop a release later, with the data archived first
    • A column type change becomes new column, batched backfill, switch, drop
    • NOT NULL becomes nullable, backfill, constrain — with the Postgres 12+ trick that avoids a table scan
    • CREATE INDEX becomes CONCURRENTLY, outside the transaction, with the invalid-index check for a failed build
    • An unbounded UPDATE becomes a bounded batch with a progress table
    • A constraint becomes NOT VALID then VALIDATE, and uniqueness becomes a concurrent index attached as a constraint
    • A missing rollback becomes a script you have actually run

    Verifies. Six checks on the rewrite before it ships, each with a file and line: NOT NULL in the same migration as the column, an unbounded backfill, CONCURRENTLY sharing a file, a destructive step with no rollback, a constraint without NOT VALID, and a drop shipped with its replacement.

    How it works

    It knows the difference between a migration that has run and one that has not, and says so first, because it decides everything: an applied migration cannot be edited — Flyway and Liquibase record a checksum — so the only option is a new migration that compensates.

    It also knows that CONCURRENTLY cannot live in a transactional migration, which is the thing that makes "just add CONCURRENTLY" fail at deploy time, and it gives the two options that actually work instead of pretending.

    Where it stops

    • SQL and Liquibase XML. Not Java-based Flyway migrations, Alembic, Rails, or DDL executed from application code at startup.
    • It does not know your table sizes, traffic or deploy window — the three things that decide batch size and whether a lock matters.
    • It cannot run your rollback or prove it works. That needs a copy of the database.

    It is the fix for what the free spring-migration-review skill finds. Run that first if you do not yet know which migrations are risky.


    Supports SQL and Liquibase XML only. No support for Alembic or Rails. Cannot verify rollback execution or determine table sizes automatically. Requires manual check of migration history tables.

    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

    No. It reads files and reports. Nothing is executed.

    Yes, and it will tell you the difference: an applied migration cannot be edited, so you get a compensating migration instead of a rewrite.

    The rewrites are written for PostgreSQL, with a section on where MySQL differs — online index builds, `ALGORITHM=` hints, no `NOT VALID` for foreign keys, and non-transactional DDL.

    No. That one finds the risky statements. This one produces the safe replacement and checks it. Use them in that order.

    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.