Apply database migrations using the Akron CLI to synchronize schema changes across SQLite, MySQL, PostgreSQL, and MongoDB.
The migrate
command applies pending database migrations to bring your database schema up to date. It tracks which migrations have been applied and only runs new ones.
akron migrate --db <database_url> [options]
Type: str (required)
Database connection URL to apply migrations to.
Type: str (optional)
Directory containing migration files. Default: ./migrations/
Type: str (optional)
Migrate to specific migration by name. Default: latest
Type: flag (optional)
Rollback the last applied migration.
Type: flag (optional)
Show which migrations would be applied without executing them.
Migration Status Check: ====================== ✓ 001_initial_schema.py - APPLIED ✓ 002_add_user_profiles.py - APPLIED • 003_add_products_table.py - PENDING • 004_update_user_schema.py - PENDING Applying migrations: ==================== → Applying 003_add_products_table.py... ✓ → Applying 004_update_user_schema.py... ✓ ✓ Applied 2 migrations successfully ✓ Database is now up to date
Migration Target: 003_add_products_table.py ========================================== → Applying 003_add_products_table.py... ✓ ✓ Migrated to target: 003_add_products_table ✓ 1 migration applied
Rollback Confirmation: ===================== Last applied migration: 004_update_user_schema.py This will execute the downgrade() function. Are you sure you want to rollback? (y/N): y → Rolling back 004_update_user_schema.py... ✓ ✓ Migration rolled back successfully
Migration Preview (DRY RUN): ============================ ✓ 001_initial_collections.py - APPLIED ✓ 002_add_user_preferences.py - APPLIED • 003_update_post_schema.py - PENDING (would apply) • 004_add_indexes.py - PENDING (would apply) Would apply 2 migrations. Run without --dry-run to execute.
Akron automatically creates a migration tracking table to record applied migrations:
This shows which migrations have been applied and which are pending.
Each migration runs in a transaction and rolls back on failure:
Migration files are checksummed to detect changes after application, preventing inconsistencies in team environments.
Always backup production databases before running migrations, especially those involving data transformations or structural changes.