v3.0.1+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2017 License: MIT Imports: 11 Imported by: 0


migrate CLI


With Go toolchain
$ go get -u -d
$ go build -tags 'postgres' -o /usr/local/bin/migrate

(todo #156)

$ brew install migrate --with-postgres
Linux (*.deb package)
$ curl -L | apt-key add -
$ echo "deb xenial main" > /etc/apt/sources.list.d/migrate.list
$ apt-get update
$ apt-get install -y migrate
Download pre-build binary (Windows, MacOS, or Linux)

Release Downloads

$ curl -L$version/migrate.$platform-amd64.tar.gz | tar xvz


$ migrate -help
Usage: migrate OPTIONS COMMAND [arg...]
       migrate [ -version | -help ]

  -source          Location of the migrations (driver://url)
  -path            Shorthand for -source=file://path 
  -database        Run migrations against this database (driver://url)
  -prefetch N      Number of migrations to load in advance before executing (default 10)
  -lock-timeout N  Allow N seconds to acquire database lock (default 15)
  -verbose         Print verbose logging
  -version         Print version
  -help            Print usage

  goto V       Migrate to version V
  up [N]       Apply all or N up migrations
  down [N]     Apply all or N down migrations
  drop         Drop everyting inside database
  force V      Set version V but don't run migration (ignores dirty state)
  version      Print current migration version

So let's say you want to run the first two migrations

$ migrate -database postgres://localhost:5432/database up 2

If your migrations are hosted on github

$ migrate -source github://mattes:personal-access-token@mattes/migrate_test \
    -database postgres://localhost:5432/database down 2

The CLI will gracefully stop at a safe point when SIGINT (ctrl+c) is received. Send SIGKILL for immediate halt.

Reading CLI arguments from somewhere else

ENV variables
$ migrate -database "$MY_MIGRATE_DATABASE"
JSON files

Check out

$ migrate -database "$(cat config.json | jq '.database')"
YAML files
$ migrate -database "$(cat config/database.yml | ruby -ryaml -e "print YAML.load(['database']")"
$ migrate -database "$(cat config/database.yml | python -c 'import yaml,sys;print yaml.safe_load(sys.stdin)["database"]')"


The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL