From 7cc954d8d2252b26a375f2b2b00017dca0f8f1fe Mon Sep 17 00:00:00 2001 From: Matthew Wraith Date: Wed, 4 Aug 2021 19:16:51 -0700 Subject: [PATCH] Set default host based on GOOS windows: localhost linux: /var/run/postgresql other (incl. macOS): /tmp --- pkg/driver/postgres/postgres.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/driver/postgres/postgres.go b/pkg/driver/postgres/postgres.go index 71b16e3..50b2cf6 100644 --- a/pkg/driver/postgres/postgres.go +++ b/pkg/driver/postgres/postgres.go @@ -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 == "" { - query.Set("host", "/var/run/postgresql") + switch runtime.GOOS { + case "windows": + hostname = "localhost" + case "linux": + query.Set("host", "/var/run/postgresql") + default: + query.Set("host", "/tmp") + } } // host param overrides url hostname