Add --wait flag (#112)

 When using dbmate as a container, since the base image is distroless, we can't do `dbmate up && dbmate wait`, which makes config a bit more cumbersome (e.g. in kubernetes an extra initContainer).

Closes #111
Closes #112
This commit is contained in:
Reuben Thomas-Davis 2019-12-31 20:47:27 +00:00 committed by Adrian Macneil
parent 98066fadaa
commit 1e45bd774c
4 changed files with 107 additions and 0 deletions

View file

@ -271,6 +271,13 @@ Waiting for database....
Creating: myapp_development
```
Alternatively you can use the `--wait` flag:
```sh
$ dbmate --wait up
Waiting for database....
Creating: myapp_development
```
If the database is still not available after 60 seconds, the command will return an error:
```sh
@ -289,6 +296,7 @@ The following command line options are available with all commands. You must use
* `--migrations-dir, -d "./db/migrations"` - where to keep the migration files.
* `--schema-file, -s "./db/schema.sql"` - a path to keep the schema.sql file.
* `--no-dump-schema` - don't auto-update the schema.sql file on migrate/rollback
* `--wait` - wait for the db to become available before executing the subsequent command
For example, before running your test suite, you may wish to drop and recreate the test database. One easy way to do this is to store your test database connection URL in the `TEST_DATABASE_URL` environment variable: