safe-migration

Plans zero-downtime database schema migrations using the expand-migrate-contract pattern.

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula --skill safe-migration-serpro-workshop-fortaleza
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-migration
Source: https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula/tree/main/.github/skills/safe-migration
Command: npx skills add https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula --skill safe-migration-serpro-workshop-fortaleza

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Changing a live database schema risks downtime, table locks, and irreversible data loss. This Skill guides you through planning schema changes—adding columns, renaming fields, backfilling data, or dropping tables—so every destructive change is split across safe, reversible deployments. ## Core Features & Use Cases - Expand-Migrate-Contract Pattern: Structures every schema change into three deployments so destructive operations never happen in a single release. - Backfill and Index Safety Rules: Enforces batched, idempotent backfills with LIMIT and pauses, plus concurrent index creation (CREATE INDEX CONCURRENTLY, ONLINE=ON). - Pre-Deployment Checklist and Output Template: Produces a migration plan with forward and rollback plans, lock-impact estimates, and red-flag warnings before you deploy. - Use Case: You need to rename a heavily used column in production. The Skill walks you through adding a new column, dual-writing, backfilling in batches, switching reads behind a feature flag, and only then dropping the old column. ## Quick Start Ask the assistant to plan a zero-downtime migration for renaming a column in your production database, including rollback and backfill steps.

Frequently Asked Questions about safe-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I rename a database column without downtime?

Never rename directly. Add a new column, dual-write to both columns, backfill historical rows in batches, switch reads to the new column behind a feature flag, and drop the old column only after the new one is authoritative for a full release cycle.

What is the expand and contract migration pattern?

Expand-migrate-contract splits every schema change into three deployments: expand adds the new structure alongside the old, migrate dual-writes and backfills while switching reads, and contract removes the old structure only after the new one is authoritative.

How do I backfill a large table without locking it?

Run backfills in batches with LIMIT, pauses between batches, and idempotent logic so reruns are safe. Never execute a single UPDATE across the whole table, and size batches according to your replica lag budget.

Does CREATE INDEX lock the table in PostgreSQL?

A plain CREATE INDEX blocks writes on the table. Use CREATE INDEX CONCURRENTLY in PostgreSQL, or ONLINE=ON in MySQL 8 and SQL Server, and monitor for lock escalation during the build.

When should I not deploy a database migration?

Do not deploy a single ALTER TABLE that fully locks a large table, a migration coupled to the app deploy that cannot be rolled back independently, an irreversible step without a backup, or a backfill rewriting all rows in one transaction.