SQL migrations utility
go get github.com/wursta/gomigrator && go install github.com/wursta/gomigrator/...@latest
gomigrator create create_some_table --migrations-dir=migrations
gomigrator up --migrations-dir=migrations --db-dsn=postgres://user:pass@dbhost:5432/dbname
gomigrator down --migrations-dir=migrations --db-dsn=postgres://user:pass@dbhost:5432/dbname
gomigrator redo --migrations-dir=migrations --db-dsn=postgres://user:pass@dbhost:5432/dbname
Create config file config.yaml
migrations_dir: "./migrations_up"
db_dsn: "postgres://test:test@localhost:5432/migrator_up_test"
Use --config
flag in commands:
gomigrator up --config=./migrations_up
You can use environment variables
GOMIGRATOR_MIGRATIONS_DIR="./migrations_up" GOMIGRATOR_DB_DSN="postgres://test:test@localhost:5432/migrator_up_test" gomigrator up
Usage:
gomigrator [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
create Create a new migration file
dbversion Get current database version
down Rollback last success migration
help Help about any command
redo Redo last success migration
status Migrations status table
up Apply new migrations
version Show version
Flags:
--config string Config file (YAML format)
--db-dsn string Database connection in DSN format
-h, --help help for gomigrator
--migrations-dir string Directory with migration files