An agnostic tool that abstracts migration operations
- postgres
- mysql
Make sure you use the project's golang version by running
asdf install
Build project by running
make build
-
database: Database URL.
Set throughDB_HOST
environment variable or by using command flag--database
. -
driver: Driver name.
Defaults to postgres.
Set through command flag--driver
. -
dir: Migrations directory.
Set through command flag--dir
.
Requires: database, dir, driver
Execute migrations by running
./bin/mgr8 apply <up|down> <number_of_migrations>
- number_of_migrations: Number of migrations to run (Optional). If not specified, runs only one.
Run a testing database with
docker compose up [-d] <database_name>
Available databases: postgres, mysql
Passing the -d
flag is optional and will run the container in detached mode, it won't block the terminal but you won't see database logs nor be able to close the container by using ctrl+c.
Point to database by setting env DB_HOST.
For postgres use DB_HOST=postgres://root:root@localhost:5432/database_name?sslmode=disable
Use make test
, make display-coverage
and make coverage-report
.
Executing migrations with postgres driver
./bin/mgr8 apply up --database=postgres://root:root@localhost:5432/core?sslmode=disable --dir=./migrations
Executing migrations with mysql driver
./bin/mgr8 apply up --database=root:root@tcp\(localhost:3306\)/core --dir=./migrations --driver=mysql