Postgres defaults to unix socket (#230)

This commit is contained in:
Matthew Wraith 2021-12-17 16:44:14 -08:00 committed by GitHub
parent fb17e8eeca
commit 81fe01b34f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/url"
"runtime"
"strings"
"github.com/amacneil/dbmate/pkg/dbmate"
@ -48,7 +49,14 @@ func connectionString(u *url.URL) string {
// default hostname
if hostname == "" {
hostname = "localhost"
switch runtime.GOOS {
case "linux":
query.Set("host", "/var/run/postgresql")
case "darwin", "freebsd", "dragonfly", "openbsd", "netbsd":
query.Set("host", "/tmp")
default:
hostname = "localhost"
}
}
// host param overrides url hostname