MySQL Migrations
Strategi migration database untuk MStore Backend menggunakan Atlas (HCL-based) dan Flyway (SQL-based).ποΈ Migration Tools
Primary: Atlas (HCL)
- Format: HCL (HashiCorp Configuration Language)
- Version Control: Git-friendly, schema as code
- Location:
third_party/migrations/atlas/schema/ - Benefit: Declarative, easy to review, supports dry-run
Fallback: Flyway (SQL)
- Format: SQL scripts
- Sequential: Numbered files (V001, V002, etc.)
- Location:
third_party/migrations/flyway/ - Benefit: Simple, direct SQL control
π Migration Naming Convention
π Migration Lifecycle
1. Create Migration File
Atlas HCL Example:2. Apply Migration
Using Atlas:3. Verify Migration
β¬οΈ Rollback Strategy
Option A: Migration Rollback (Preferred)
Option B: Manual Rollback (Emergency)
- Stop application
- Restore from backup:
- Re-apply migrations to stable version
- Verify data integrity
- Restart application
Option C: Point-in-Time Recovery
β Pre-Migration Checklist
- Backup database
- Test migration on staging
- Verify rollback procedure
- Notify team
- Schedule maintenance window
- Review migration script for syntax errors
- Check for data type compatibility
β Post-Migration Checklist
- Verify schema changes:
DESCRIBE table_name; - Check index creation:
SHOW INDEXES FROM table_name; - Validate constraints:
SHOW CREATE TABLE table_name; - Run smoke tests
- Monitor performance
- Check application logs
- Verify data integrity
π Best Practices
DO β
- Use version control for all migrations
- Test migrations on staging first
- Keep migrations small & focused
- Document complex migrations
- Backup before major migrations
- Use transactions for data migrations
- Index foreign keys
- Use soft delete for audit trails
DONβT β
- Modify production data directly
- Skip testing migrations
- Use large batch updates without pagination
- Drop tables without backup
- Ignore migration errors
- Mix schema & data migrations
- Use reserved SQL keywords as column names