# Spring Migration Safe Rewrite

> Turns a flagged database migration into the safe expand-contract sequence: add nullable, backfill in batches, switch reads, drop a release later. Covers CONCURRENTLY outside the transaction, NOT VALID constraints and rollback scripts, with a verifier for the rewrite. Use when a scan found a destruct

Spring Migration Safe Rewrite is a paid AI agent skill on Agensi by Puneet Swarup, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $19 (one-time purchase)
- Creator: [Puneet Swarup](https://www.agensi.io/creators/puneet-swarup)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Version: 1.0.1
- Last updated: 2026-11-27
- Security: scan passed (2026-11-27); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/spring-migration-safe-rewrite
- Tags: database, security, flyway, liquibase, postgresql, mysql, sql, database-migration

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

---

## Known limitations

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 this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Spring Migration Safe Rewrite skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### Does it run migrations or touch my database?

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

### Will it work if the migration already ran in production?

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

### Postgres only?

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.

### Is this the same as the free spring-migration-review skill?

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

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
