Migration engine for PostgreSQL written in Go.
- Migrations are written with sql
- Migrate up and down to specific version
- Migrations are built into one executable
- All sql files are embedded resources
When migration is added gomigo does two things:
- generates a folder with following structure:
├── migrations
└── 20200812012658_initial
├── up.sql
├── down.sql
└── migrate.go
- registers migration in database
up.sql is executed to update database
down.sql is executed to downgrade database
-
Install dependencies
-
Install gomigo
-
Create Go Module
-
Execute in command line:
Usage:
gomigo [options] [command]
Commands:
init
initializes migrations
clean
cleans migrations
add
adds new migration (requires -name option)
remove
removes a migration (requires -name option)
up
upgrades to specific version (requires -version option)
down
downgrades to specific version (requires -version option)
update
updates migrations
Options:
-db string
database connection string
-module string
module name
-name string
migration name
-version int
version to upgrade/downgrade