mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
Fix wait command for servers with no postgres database (#90)
Currently the `dbmate wait` command fails if the `postgres` system database does not exist (which is common on DigitalOcean, and perhaps other hosting providers). This command is intended to verify that the postgres server is available, and not whether or not the user's database exists. Therefore, we will update this command to simply ignore the `database "foo" does not exist` error and treat this as the server being ready. Fixes #78
This commit is contained in:
parent
aa72a39a29
commit
b69a3d487a
1 changed files with 16 additions and 2 deletions
|
|
@ -177,11 +177,25 @@ func (drv PostgresDriver) DeleteMigration(db Transaction, version string) error
|
|||
// Ping verifies a connection to the database server. It does not verify whether the
|
||||
// specified database exists.
|
||||
func (drv PostgresDriver) Ping(u *url.URL) error {
|
||||
db, err := drv.openPostgresDB(u)
|
||||
// attempt connection to primary database, not "postgres" database
|
||||
// to support servers with no "postgres" database
|
||||
// (see https://github.com/amacneil/dbmate/issues/78)
|
||||
db, err := drv.Open(u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer mustClose(db)
|
||||
|
||||
return db.Ping()
|
||||
err = db.Ping()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ignore 'database "foo" does not exist' error
|
||||
pqErr, ok := err.(*pq.Error)
|
||||
if ok && pqErr.Code == "3D000" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue