mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2026-02-02 17:35:08 +01:00
Postgres defaults to unix socket with no host #229
Closes #229 When there's no host given in a postgres connection url, use the unix domain default socket. Previously, the default was a localhost TCP connection. This default behavior is more in line with standard postgres clients out there, like psql.
This commit is contained in:
parent
6243c2b9a9
commit
8175745cfe
2 changed files with 5 additions and 5 deletions
|
|
@ -48,7 +48,7 @@ func connectionString(u *url.URL) string {
|
||||||
|
|
||||||
// default hostname
|
// default hostname
|
||||||
if hostname == "" {
|
if hostname == "" {
|
||||||
hostname = "localhost"
|
query.Set("host", "/var/run/postgresql")
|
||||||
}
|
}
|
||||||
|
|
||||||
// host param overrides url hostname
|
// host param overrides url hostname
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func TestConnectionString(t *testing.T) {
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
// defaults
|
// defaults
|
||||||
{"postgres:///foo", "postgres://localhost:5432/foo"},
|
{"postgres:///foo", "postgres://:5432/foo?host=%2Fvar%2Frun%2Fpostgresql"},
|
||||||
// support custom url params
|
// support custom url params
|
||||||
{"postgres://bob:secret@myhost:1234/foo?bar=baz", "postgres://bob:secret@myhost:1234/foo?bar=baz"},
|
{"postgres://bob:secret@myhost:1234/foo?bar=baz", "postgres://bob:secret@myhost:1234/foo?bar=baz"},
|
||||||
// support `host` and `port` via url params
|
// support `host` and `port` via url params
|
||||||
|
|
@ -85,11 +85,11 @@ func TestConnectionArgsForDump(t *testing.T) {
|
||||||
expected []string
|
expected []string
|
||||||
}{
|
}{
|
||||||
// defaults
|
// defaults
|
||||||
{"postgres:///foo", []string{"postgres://localhost:5432/foo"}},
|
{"postgres:///foo", []string{"postgres://:5432/foo?host=%2Fvar%2Frun%2Fpostgresql"}},
|
||||||
// support single schema
|
// support single schema
|
||||||
{"postgres:///foo?search_path=foo", []string{"--schema", "foo", "postgres://localhost:5432/foo"}},
|
{"postgres:///foo?search_path=foo", []string{"--schema", "foo", "postgres://:5432/foo?host=%2Fvar%2Frun%2Fpostgresql"}},
|
||||||
// support multiple schemas
|
// support multiple schemas
|
||||||
{"postgres:///foo?search_path=foo,public", []string{"--schema", "foo", "--schema", "public", "postgres://localhost:5432/foo"}},
|
{"postgres:///foo?search_path=foo,public", []string{"--schema", "foo", "--schema", "public", "postgres://:5432/foo?host=%2Fvar%2Frun%2Fpostgresql"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue