From 079523c25f8b476c283bd7342a2ef9a7355422b6 Mon Sep 17 00:00:00 2001 From: Nikita Konev Date: Thu, 26 Mar 2020 18:25:45 +0300 Subject: [PATCH] Add --wait-timeout option (#127) Closes #127 --- README.md | 8 ++++---- main.go | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a9fb61..faec06f 100644 --- a/README.md +++ b/README.md @@ -284,12 +284,12 @@ Waiting for database.... Creating: myapp_development ``` -If the database is still not available after 60 seconds, the command will return an error: +You can customize the timeout using `--wait-timeout` (default 60s). If the database is still not available, the command will return an error: ```sh -$ dbmate wait -Waiting for database............................................................ -Error: unable to connect to database: pq: role "foobar" does not exist +$ dbmate --wait-timeout=5s wait +Waiting for database..... +Error: unable to connect to database: dial tcp 127.0.0.1:5432: connect: connection refused ``` Please note that the `wait` command does not verify whether your specified database exists, only that the server is available and ready (so it will return success if the database server is available, but your database has not yet been created). diff --git a/main.go b/main.go index d8bc1e8..04a4e76 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,11 @@ func NewApp() *cli.App { Name: "wait", Usage: "wait for the db to become available before executing the subsequent command", }, + cli.DurationFlag{ + Name: "wait-timeout", + Usage: "timeout for --wait flag", + Value: dbmate.DefaultWaitTimeout, + }, } app.Commands = []cli.Command{ @@ -177,6 +182,10 @@ func action(f func(*dbmate.DB, *cli.Context) error) cli.ActionFunc { db.MigrationsDir = c.GlobalString("migrations-dir") db.SchemaFile = c.GlobalString("schema-file") db.WaitBefore = c.GlobalBool("wait") + overrideTimeout := c.GlobalDuration("wait-timeout") + if overrideTimeout != 0 { + db.WaitTimeout = overrideTimeout + } return f(db, c) }