Yet another database migration tool written in Erlang.
- Manages applied/unapplied migrations
- Runs a migration with multiple queries under a transaction whenever possible
- MySQL
- PostgreSQL
- With Erlang/OTP runtime, download release binary from releases.
- Without Erlang/OTP runtime, pull docker image with
docker pull yowcow/migerl
.
Usage: migerl [-c <config>] [-e [<env>]] [-d [<dir>]] [-t [<title>]]
[-a [<all>]] [-v [<version>]] [-h [<help>]] [command ...]
-c, --config Config file
-e, --env Env name in config [default: default]
-d, --dir Migration script directory [default: scripts]
-t, --title Migration title [default: untitled]
-a, --all Apply/Unapply all [default: false]
-v, --version Print version [default: false]
-h, --help Print this help [default: false]
command Commands to execute (e.g. init, new, status, up, down)
Initialize:
migerl -c path/to/config init
Create a new migration file:
migerl -c path/to/config -t the_new_migration new
Show current status:
migerl -c path/to/config status
Apply 1 migration:
migerl -c path/to/config up
Undo 1 migration:
migerl -c path/to/config down
Apply all unapplied migrations:
migerl -c path/to/config -a up
Undo all applied migrations:
migerl -c path/to/config -a down
Should be in erlang proplist:
[
{"default", [
{dialect, mysql},
{config, [
{host, "127.0.0.1"},
{port, 3306},
{user, "test-migration-user"},
{password, "test-user-p@ssw0rd"},
{database, "test_db"},
{queries, [
"SET NAMES utf8mb4"
]}
]}
]},
{"devel", [
{dialect, mysql},
{config, [
{host, "devel-db-host"},
{port, 3306},
{user, "devel-migration-user"},
{password, "devel-user-p@ssw0rd"},
{database, "devel_db"},
{queries, [
"SET NAMES utf8mb4"
]}
]}
]},
{"prod", [
{dialect, mysql},
{config, [
{host, "prod-db-host"},
{port, 3306},
{user, "prod-migration-user"},
{password, "devel-user-p@ssw0rd"},
{database, "prod_db"},
{queries, [
"SET NAMES utf8mb4"
]}
]}
]},
{"postgresql", [
{dialect, postgres},
{config, #{
host => "localhost",
username => "postgres",
password => "",
database => "migerl_test",
port => 5432
}}
]}
].
rebar3 escriptize
See Makefile
, docker.mk
for development.