github.com/pulumi/golang-migrate@v3.5.4+incompatible/cli/README.md (about)

     1  # migrate CLI
     2  
     3  ## Installation
     4  
     5  #### Download pre-build binary (Windows, MacOS, or Linux)
     6  
     7  [Release Downloads](https://github.com/golang-migrate/migrate/releases)
     8  
     9  ```
    10  $ curl -L https://github.com/golang-migrate/migrate/releases/download/$version/migrate.$platform-amd64.tar.gz | tar xvz
    11  ```
    12  
    13  #### MacOS
    14  
    15  We have not released support for homebrew yet, but there is a live issue here: [todo #156](https://github.com/mattes/migrate/issues/156)
    16  
    17  Any help to make this happen would be appreciated!
    18  
    19  #### Linux (*.deb package)
    20  
    21  ```
    22  $ curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
    23  $ echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ xenial main" > /etc/apt/sources.list.d/migrate.list
    24  $ apt-get update
    25  $ apt-get install -y migrate
    26  ```
    27  
    28  #### With Go toolchain
    29  
    30  ```
    31  $ go get -u -d github.com/golang-migrate/migrate/cli
    32  $ cd $GOPATH/src/github.com/golang-migrate/migrate/cli
    33  $ dep ensure
    34  $ go build -tags 'postgres' -o /usr/local/bin/migrate github.com/golang-migrate/migrate/cli
    35  ```
    36  
    37  ##### Notes:
    38  1. This example builds the cli which will only work with postgres.  In order
    39  to build the cli for use with other databases, replace the `postgres` build tag
    40  with the appropriate database tag(s) for the databases desired.  The tags
    41  correspond to the names of the sub-packages underneath the
    42  [`database`](../database) package.
    43  1. Similarly to the database build tags, if you need to support other sources, use the appropriate build tag(s).
    44  1. Support for build constraints will be removed in the future: https://github.com/golang-migrate/migrate/issues/60
    45  
    46  
    47  ## Usage
    48  
    49  ```
    50  $ migrate -help
    51  Usage: migrate OPTIONS COMMAND [arg...]
    52         migrate [ -version | -help ]
    53  
    54  Options:
    55    -source          Location of the migrations (driver://url)
    56    -path            Shorthand for -source=file://path
    57    -database        Run migrations against this database (driver://url)
    58    -prefetch N      Number of migrations to load in advance before executing (default 10)
    59    -lock-timeout N  Allow N seconds to acquire database lock (default 15)
    60    -verbose         Print verbose logging
    61    -version         Print version
    62    -help            Print usage
    63  
    64  Commands:
    65    create [-ext E] [-dir D] [-seq] [-digits N] [-format] NAME
    66                 Create a set of timestamped up/down migrations titled NAME, in directory D with extension E.
    67                 Use -seq option to generate sequential up/down migrations with N digits.
    68                 Use -format option to specify a Go time format string.
    69    goto V       Migrate to version V
    70    up [N]       Apply all or N up migrations
    71    down [N]     Apply all or N down migrations
    72    drop         Drop everyting inside database
    73    force V      Set version V but don't run migration (ignores dirty state)
    74    version      Print current migration version
    75  ```
    76  
    77  
    78  So let's say you want to run the first two migrations
    79  
    80  ```
    81  $ migrate -source file://path/to/migrations -database postgres://localhost:5432/database up 2
    82  ```
    83  
    84  If your migrations are hosted on github
    85  
    86  ```
    87  $ migrate -source github://mattes:personal-access-token@mattes/migrate_test \
    88      -database postgres://localhost:5432/database down 2
    89  ```
    90  
    91  The CLI will gracefully stop at a safe point when SIGINT (ctrl+c) is received.
    92  Send SIGKILL for immediate halt.
    93  
    94  
    95  
    96  ## Reading CLI arguments from somewhere else
    97  
    98  ##### ENV variables
    99  
   100  ```
   101  $ migrate -database "$MY_MIGRATE_DATABASE"
   102  ```
   103  
   104  ##### JSON files
   105  
   106  Check out https://stedolan.github.io/jq/
   107  
   108  ```
   109  $ migrate -database "$(cat config.json | jq '.database')"
   110  ```
   111  
   112  ##### YAML files
   113  
   114  ````
   115  $ migrate -database "$(cat config/database.yml | ruby -ryaml -e "print YAML.load(STDIN.read)['database']")"
   116  $ migrate -database "$(cat config/database.yml | python -c 'import yaml,sys;print yaml.safe_load(sys.stdin)["database"]')"
   117  ```