yuri-gama / mgr8

Agnostic tool that abstracts migration operations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mgr8

An agnostic tool that abstracts migration operations

Suported databases

  • postgres
  • mysql

How to use

Requirements

Setup

Make sure you use the project's golang version by running

asdf install

Build project by running

make build

Run commands

Set needed variables

  • database: Database URL.
    Set through DB_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.

Execute migrations

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.

Develop

Requirements

Run a database container

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

Testing

Use make test, make display-coverage and make coverage-report.

Snippets

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

About

Agnostic tool that abstracts migration operations


Languages

Language:Go 97.8%Language:Makefile 2.2%