Skip to main content

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

Examples:

πŸ”„ Migration Lifecycle

1. Create Migration File

Atlas HCL Example:

2. Apply Migration

Using Atlas:
Using Flyway:

3. Verify Migration


⬇️ Rollback Strategy

Option A: Migration Rollback (Preferred)

Option B: Manual Rollback (Emergency)

  1. Stop application
  2. Restore from backup:
  3. Re-apply migrations to stable version
  4. Verify data integrity
  5. 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

Data Seeding

Seed data strategy

MySQL Schema

Complete schema reference

Backup & Restore

Backup procedures

ERD Diagram

Entity relationship diagram