README
¶
migrate CLI
Installation
Download pre-built binary (Windows, MacOS, or Linux)
$ curl -L https://github.com/c2pc/migrate/releases/download/$version/migrate.$os-$arch.tar.gz | tar xvz
MacOS
$ brew install c2pc
Windows
Using scoop
$ scoop install migrate
Linux (*.deb package)
$ curl -L https://packagecloud.io/c2pc/migrate/gpgkey | apt-key add -
$ echo "deb https://packagecloud.io/c2pc/migrate/ubuntu/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/migrate.list
$ apt-get update
$ apt-get install -y migrate
With Go toolchain
Versioned
$ go get -u -d github.com/c2pc/migrate/cmd/migrate
$ cd $GOPATH/src/github.com/c2pc/migrate/cmd/migrate
$ git checkout $TAG # e.g. v4.1.0
$ # Go 1.15 and below
$ go build -tags 'yml' -ldflags="-X main.Version=$(git describe --tags)" -o $GOPATH/bin/migrate $GOPATH/src/github.com/c2pc/migrate/cmd/migrate
$ # Go 1.16+
$ go install -tags 'yml' github.com/c2pc/migrate/cmd/migrate@$TAG
Unversioned
$ # Go 1.15 and below
$ go get -tags 'yml' -u github.com/c2pc/migrate/cmd/migrate
$ # Go 1.16+
$ go install -tags 'yml' github.com/c2pc/migrate/cmd/migrate@latest
Notes
- Requires a version of Go that supports modules. e.g. Go 1.11+
- These examples build the cli which will only work with yml. In order
to build the cli for use with other files, replace the
ymlbuild tag with the appropriate file tag(s) for the files desired. The tags correspond to the names of the sub-packages underneath thefilepackage. - Similarly to the file build tags, if you need to support other sources, use the appropriate build tag(s).
- Support for build constraints will be removed in the future: https://github.com/c2pc/migrate/issues/60
- For versions of Go 1.15 and lower, make sure you're not installing the
migrateCLI from a module. e.g. there should not be anygo.modfiles in your current directory or any directory from your current directory to the root
Usage
$ migrate -help
Usage: migrate OPTIONS COMMAND [arg...]
migrate [ -version | -help ]
Options:
-source Location of the migrations (driver://url)
-path Shorthand for -source=file://path
-file Run migrations against this file (driver://url)
-prefetch N Number of migrations to load in advance before executing (default 10)
-lock-timeout N Allow N seconds to acquire file lock (default 15)
-verbose Print verbose logging
-version Print version
-help Print usage
Commands:
create [-ext E] [-dir D] [-seq] [-digits N] [-format] NAME
Create a set of timestamped up/down migrations titled NAME, in directory D with extension E.
Use -seq option to generate sequential up/down migrations with N digits.
Use -format option to specify a Go time format string.
goto V Migrate to version V
up [N] Apply all or N up migrations
down [N] Apply all or N down migrations
drop Drop everything inside file
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 -source file://path/to/migrations -file yml://./config.yml up 2
If your migrations are hosted on github
$ migrate -source github://c2pc:personal-access-token@c2pc/migrate_test \
-file yml://./config.yml 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 -file "$MY_MIGRATE_DATABASE"
JSON files
Check out https://stedolan.github.io/jq/
$ migrate -file "$(cat config.json | jq -r '.file')"
YAML files
$ migrate -file "$(cat config/file.yml | ruby -ryaml -e "print YAML.load(STDIN.read)['file']")"
$ migrate -file "$(cat config/file.yml | python -c 'import yaml,sys;print yaml.safe_load(sys.stdin)["file"]')"
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.