What problem does it solve?
This Skill provides best practices for managing database schema changes using Alembic, addressing issues like irreversible migrations, data loss during rollbacks, and inconsistent schema evolution. It ensures safe, reproducible, and testable database updates, minimizing downtime and data integrity risks.
Core Features & Use Cases
- Alembic Setup & Usage: Guides on configuring
alembic/env.py and creating migrations with alembic revision --autogenerate.
- Safe Schema Changes: Provides patterns for safely adding columns (nullable first), modifying column types, and handling foreign key changes.
- Data Migrations: Explains how to perform data transformations within migrations, including multi-phase approaches for complex data changes.
- Migration Testing: Offers patterns for writing
pytest tests to verify migrations can upgrade and downgrade, and preserve data integrity.
- Use Case: A backend team needs to add a new
phone column to the users table and migrate existing status values. This skill guides them to add the column as nullable first, then update existing data, and finally make it non-nullable, ensuring no data loss and a smooth deployment.
Quick Start
Create a new Alembic migration to add a phone column to the users table, ensuring it's added as nullable first.