Maestro is a powerful Go library and CLI tool designed for seamless database migration management.
Just as a maestro orchestrates a symphony, maestro orchestrates your database changes, conducting migrations with precision and grace. It ensures your database schema evolves smoothly, keeping all your environments in perfect harmony while maintaining a clear record of every change.
# Install as CLI tool
go install github.com/maestro-go/maestro@latest
# Create a new migration
maestro create add_users_table -m ./migrations --with-down
# Run migrations
maestro migrate- π¦ Installation
- ποΈ Supported Databases
- β¨ Key Features
- π Migrations
β οΈ Warnings- π Documentation
- π€ Contributing
- π License
go install github.com/maestro-go/maestro@latestgo get github.com/maestro-go/maestro/core- β PostgreSQL
- β CockroachDB
- β SQLite3
- π§ MySQL
- π§ ClickHouse
- β¨ Manage up/down migrations effortlessly
- π οΈ Repair migrations seamlessly
- π Validate migrations with MD5 checksums
- πͺ Utilize a flexible hooks system
- π Track migration history clearly
- π Built-in SSH tunnel support
Maestro uses a simple naming convention for migration files:
π migrations/
βββ π V001_create_users.sql # Up migration
βββ π V001_create_users.down.sql # Down migration (optional)
βββ π V002_add_email_column.sql
βββ π V002_add_email_column.down.sql
If you're using hooks, the recommended folder structure is:
π migrations/
βββ π V001_example.sql
βββ π V001_example.down.sql
βββ π before/
βββ π beforeEach/
βββ π beforeVersion/
βββ π afterVersion/
βββ π afterEach/
βββ π after/
βββ π repeatable/
βββ π repeatableDown/
Create new migrations using the CLI:
maestro create add_users_table -m ./migrations --with-downControl which migrations to run using destination:
# Run migrations up to 10
maestro migrate --destination 10
# Run migrations down to 5
maestro migrate --down --destination 5When performing a downward migration, ensure that each upward migration has a corresponding downward migration file. Failure to do so may result in inconsistencies.
If you encounter checksum mismatches or other issues with your migration history, you can use the repair command to fix them. This command recalculates and updates the checksums of your migration files, ensuring that the recorded checksums match the actual files.
maestro repairNote: Using repair is not recommended as the primary fix. However, if you need to change old migrations and hooks cannot solve the problem, the repair command can be used to maintain the integrity of your migration history.
Check the current migrations status, like latest applied migration and failed migrations:
maestro statusMaestro supports the use of templates to simplify and standardize your migration files. Templates allow you to define reusable content that can be dynamically replaced with specific values during migration execution.
To use templates, create a template file in your migrations directory with the .template.sql extension. For example:
π migrations/
βββ π V001_create_users.sql
βββ π V001_create_users.down.sql
βββ π table_template.template.sql
In your migration files, you can reference the template using the {{template_name, value1, value2}} syntax. Maestro will replace the template placeholders with the provided values.
Example template file (table_template.template.sql):
CREATE TABLE $1 (
id SERIAL PRIMARY KEY,
$2 VARCHAR(255) NOT NULL,
$3 VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Example migration file using the template:
{{table_template, users, name, email}}
Maestro will replace {{table_template, users, name, email}} with the content of table_template.template.sql, resulting in:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);You can force migrations using the force flag/config. However, it is not compatible with the in-transaction flag/config. When using transactions, forcing a migration that encounters an error will result in the entire transaction being rolled back.
Detailed documentation is available:
We welcome contributions! Please read our:
This project is licensed under the MIT License - see the LICENSE file for details.