Database Migrator
Overview
Automate database schema migrations and data transfers across environments and database engines with safety checks, rollback capabilities, and detailed audit trails.
When to Use
- •Migrating from one database engine to another (e.g., MySQL to PostgreSQL)
- •Applying schema changes across dev/staging/production environments
- •Syncing data between Supabase projects
- •Running zero-downtime migrations for live production systems
- •Generating rollback scripts before risky schema changes
Instructions
- •Accept inputs: source DB connection string, target DB connection string, migration type (schema/data/both), dry_run flag.
- •Connect to source and target databases and verify connectivity.
- •Diff the source schema against the target to identify: new tables, dropped tables, column changes, index changes, constraint changes.
- •Generate migration SQL scripts (up and down/rollback versions).
- •If dry_run=true, output the migration plan without executing.
- •If dry_run=false, execute migration in a transaction; roll back on any error.
- •Validate row counts and spot-check data integrity post-migration.
- •Return a migration report: tables affected, rows migrated, duration, rollback script location.
Environment
code
SOURCE_DB_URL=postgresql://user:pass@source-host:5432/dbname TARGET_DB_URL=postgresql://user:pass@target-host:5432/dbname MIGRATION_DIR=./migrations DRY_RUN=true BACKUP_BEFORE_MIGRATE=true
Examples
Input:
code
source: supabase_project_a target: supabase_project_b type: schema_and_data tables: [users, orders, products] dry_run: false
Output:
code
Migration completed successfully. Tables migrated: 3 Rows transferred: 142,831 Duration: 4m 12s Rollback script: ./migrations/rollback_20260218.sql Integrity check: PASSED