From 95ff9152a4b95059c0fb341833ba7138b29c0610 Mon Sep 17 00:00:00 2001 From: Phil Constantinou Date: Mon, 22 Jan 2024 11:47:14 -0800 Subject: [PATCH] Fix support for sslmode too --- backends/postgres/postgres_backend.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backends/postgres/postgres_backend.go b/backends/postgres/postgres_backend.go index 0331b2d..c077823 100644 --- a/backends/postgres/postgres_backend.go +++ b/backends/postgres/postgres_backend.go @@ -7,6 +7,7 @@ import ( "fmt" "net/url" "os" + "strings" "sync" "time" @@ -337,10 +338,19 @@ func (p *PgBackend) initializeDB() (err error) { return } - sslMode := "verify-ca" // nil TLSConfig means "sslmode=disable" was set on the connection + sslMode := "verify-ca" if pgxCfg.TLSConfig == nil { sslMode = "disable" + } else if pgxCfg.TLSConfig.InsecureSkipVerify { + sslMode = "require" + } + if dbURL, err := url.Parse(pgxCfg.ConnString()); err == nil && + strings.HasPrefix(dbURL.Scheme, "postgres") { + val := dbURL.Query() + if v := val.Get("sslmode"); v != "" { + sslMode = v // set sslmode from existing connection string + } } pqConnectionString := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s&x-migrations-table=neoq_schema_migrations",