--- name: "MySQL Migration Safety" description: "Ensures database schema migrations are safe, non-blocking, and backwards-compatible." --- # Skill: MySQL Migration Safety ## 1. Purpose Avoid database downtime, long table locks, or transactional data loss when applying migrations using Alembic in production. ## 2. When to Use Before generating or applying Alembic database migration scripts. ## 3. Step-by-Step Checklist 1. **Backward Compatibility**: Ensure new columns are added as nullable or with a default value. 2. **Table Locking Check**: Avoid adding indexes or modifying column types directly on large tables (e.g. over 100k rows) during peak hours. Use online schema change patterns if necessary. 3. **Data Migrations**: Separate schema changes (DDL) from data transformation changes (DML) into distinct migration steps. 4. **Rollback Script**: Ensure `downgrade()` in Alembic is fully implemented and tested. 5. **Alembic History**: Run `alembic history` to confirm there are no branching version conflicts.