- Home
- Skills
- Data & Databases
- Migration Guard: catch downtime-causing database migrations
More screenshots
Works with the AI Agents you already use
Migration Guard: catch downtime-causing database migrations
Migration Guard checks new or changed migrations on your branch and gives a ✅ SAFE / ⚠️ REVIEW / ⛔ BLOCK verdict.
Free
Migration Guard: catch downtime-causing database migrations
Example session with this skill installed
I just wrote a new migration in alembic/versions/b002_order_status.py. Can you check it's safe to deploy? The orders table has about 40 million rows and we're on PostgreSQL 15.
- Read your context and instructions
- Compiled the migration guard
I checked `alembic/versions/b002_order_status.py`, the only new migration on this branch, assuming PostgreSQL 15 and ~40M rows in `orders`.
## Migration Guard: ⛔ BLOCK
**alembic/versions/b002_order_status.py** (Alembic)
| | Issue | Where | Why it matters |
|---|---|---|---|
| ⛔ | NOT NULL column with only a Python-side `default=` | line 14, `orders.status` | `default=` never reaches the database, so the 40M existing rows have no value and the migration fails |
| ⛔ | Index built without CONCURRENTLY | line 15, `orders.customer_id` | takes a SHARE lock: every INSERT/UPDATE/DELETE on `orders` waits until the index is built |
| ⛔ | Column dropped while code still uses it | line 16, `orders.coupon_code` | breaks the running app mid-deploy; the data is gone for good |
| ⚠️ | Type change `Numeric(10,2)` → `Numeric(12,2)` | line 17, `orders.total` | same scale, so it's metadata-only on Postgres (no rewrite), but it still needs a brief lock, so add `lock_timeout` |
| ⚠️ | Empty `downgrade()` on a destructive migration | line 20 | no way back if the deploy goes wrong |
| ℹ️ | No `lock_timeout` | `upgrade()` | a lock waiting behind a slow query freezes every query on `orders` |
**Code still using `orders.coupon_code`:** `shop/checkout.py:6` (`order.coupon_code = code`) and `shop/models/order.py:10` (the model column, so loading any `Order` would fail).
### Safe version: split into three migrations
`b002_order_status.py`
```python
```python
def upgrade():
op.execute("SET lock_timeout = '5s'")
```
# A constant server default is instant on PG 11+ and fills existing rows
op.add_column("orders", sa.Column("status", sa.String(20), nullable=False,
server_default="pending"))
op.alter_column("orders", "total", type_=sa.Numeric(12, 2),
existing_type=sa.Numeric(10, 2))
```python
def downgrade():
op.execute("SET lock_timeout = '5s'")
```
# Narrowing rewrites the table and fails if any total no longer fits
op.alter_column("orders", "total", type_=sa.Numeric(10, 2),
existing_type=sa.Numeric(12, 2))
```
op.drop_column("orders", "status")
```
```
`b003_orders_customer_id_index.py`
```python
def upgrade():
with op.get_context().autocommit_block(): # CONCURRENTLY can't run in a transaction
op.create_index("ix_orders_customer_id", "orders", ["customer_id"],
postgresql_concurrently=True)
def downgrade():
with op.get_context().autocommit_block():
op.drop_index("ix_orders_customer_id", table_name="orders",
postgresql_concurrently=True)
```
`b004_drop_orders_coupon_code.py`: ship in a later release
```python
def upgrade():
op.execute("SET lock_timeout = '5s'")
op.drop_column("orders", "coupon_code")
def downgrade():
# Restores the column, not the data
op.add_column("orders", sa.Column("coupon_code", sa.String(32), nullable=True))
```
### Deploy plan
1. **Run b002 + b003:** safe with today's code. Reads and writes keep working while the index builds.
2. **Deploy code:** add `status` to the model and stop reading and writing `coupon_code`.
3. **Export `coupon_code` data** if anyone needs it. The drop can't be undone.
4. **Run b004** in the next release.
**Assumptions:** PostgreSQL 15, ~40M rows in `orders`. If you're on MySQL or an older Postgres, tell me and I'll treat the type change as a full table rewrite.
Connects securely to your tools. The creator never sees your data.
About this skill
Some migrations look harmless and still take production down. Migration Guard checks new or changed migrations on your branch and gives a ✅ SAFE / ⚠️ REVIEW / ⛔ BLOCK verdict.
What it catches:
- indexes built without CONCURRENTLY, including the ones Django and Rails create for you
- NOT NULL columns with no database default (including Alembic's Python-only default=)
- type changes and volatile defaults that rewrite the whole table
- dropped or renamed columns, with the files in your code that still use them
- foreign keys and constraints validated under lock
- unbatched backfills and missing rollbacks
What you get: a rewrite in your own framework (Alembic, Django, Rails, Knex, raw SQL; Prisma and Flyway via SQL) and a step-by-step deploy plan. PostgreSQL is fully supported; MySQL gets the core rules.
Read-only and safe: it never connects to your database, never runs migrations, and makes no network calls. Tested on 1,760 real migrations from large open-source projects.
Read-only. Cannot connect to live DBs. Table sizes must be provided or inferred from docs. SQL generation requires a working local environment for the specific ORM.
How to use
- 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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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 8 days ago
- Free with an Agensi account
- Software
Git
Python 3.9+
Run your agent from the project root. Read-only by default: it never connects to your database or runs migrations, and only edits files if you ask it to apply the safe version.
Permissions
File Scopes
Shell runs the bundled Python checker and read-only git commands (git status / git diff) to find changed migrations. Files are read to analyse migrations and search code. Writing happens only if the user asks to apply the safe version. No network, no database connection, no environment variables.
What's inside
Creator
Liji Mariyam mathew
Frequently Asked Questions
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.