github.com/yuukihogo/migrate@v3.0.0+incompatible/cli/README.md (about)

     1  # migrate CLI
     2  
     3  ## Installation
     4  
     5  #### With Go toolchain
     6  
     7  ```
     8  $ go get -u -tags 'postgres' -o migrate github.com/mattes/migrate/cli
     9  ```
    10  
    11  #### MacOS
    12  
    13  ([todo #156](https://github.com/mattes/migrate/issues/156))
    14  
    15  ```
    16  $ brew install migrate --with-postgres
    17  ```
    18  
    19  #### Linux (*.deb package)
    20  
    21  ```
    22  $ curl -L https://packagecloud.io/mattes/migrate/gpgkey | apt-key add -
    23  $ echo "deb https://packagecloud.io/mattes/migrate/ubuntu/ xenial main" > /etc/apt/sources.list.d/migrate.list
    24  $ apt-get update
    25  $ apt-get install -y migrate
    26  ```
    27  
    28  #### Download pre-build binary (Windows, MacOS, or Linux)
    29  
    30  [Release Downloads](https://github.com/mattes/migrate/releases)
    31  
    32  ```
    33  $ curl -L https://github.com/mattes/migrate/releases/download/$version/migrate.$platform-amd64.tar.gz | tar xvz
    34  ```
    35  
    36  
    37  
    38  ## Usage
    39  
    40  ```
    41  $ migrate -help
    42  Usage: migrate OPTIONS COMMAND [arg...]
    43         migrate [ -version | -help ]
    44  
    45  Options:
    46    -source          Location of the migrations (driver://url)
    47    -path            Shorthand for -source=file://path 
    48    -database        Run migrations against this database (driver://url)
    49    -prefetch N      Number of migrations to load in advance before executing (default 10)
    50    -lock-timeout N  Allow N seconds to acquire database lock (default 15)
    51    -verbose         Print verbose logging
    52    -version         Print version
    53    -help            Print usage
    54  
    55  Commands:
    56    goto V       Migrate to version V
    57    up [N]       Apply all or N up migrations
    58    down [N]     Apply all or N down migrations
    59    drop         Drop everyting inside database
    60    force V      Set version V but don't run migration (ignores dirty state)
    61    version      Print current migration version
    62  ```
    63  
    64  
    65  So let's say you want to run the first two migrations
    66  
    67  ```
    68  $ migrate -database postgres://localhost:5432/database up 2
    69  ```
    70  
    71  If your migrations are hosted on github
    72  
    73  ```
    74  $ migrate -source github://mattes:personal-access-token@mattes/migrate_test \
    75      -database postgres://localhost:5432/database down 2
    76  ```
    77  
    78  The CLI will gracefully stop at a safe point when SIGINT (ctrl+c) is received.
    79  Send SIGKILL for immediate halt.
    80  
    81  
    82  
    83  ## Reading CLI arguments from somewhere else
    84  
    85  ##### ENV variables
    86  
    87  ```
    88  $ migrate -database "$MY_MIGRATE_DATABASE"
    89  ```
    90  
    91  ##### JSON files
    92  
    93  Check out https://stedolan.github.io/jq/
    94  
    95  ```
    96  $ migrate -database "$(cat config.json | jq '.database')"
    97  ```
    98  
    99  ##### YAML files
   100  
   101  ````
   102  $ migrate -database "$(cat config/database.yml | ruby -ryaml -e "print YAML.load(STDIN.read)['database']")"
   103  $ migrate -database "$(cat config/database.yml | python -c 'import yaml,sys;print yaml.safe_load(sys.stdin)["database"]')"
   104  ```