Skip to content

Commit

Permalink
Automatically add sslmode=disable to postgres connection string when …
Browse files Browse the repository at this point in the history
…upgrading
  • Loading branch information
tulir committed Dec 19, 2023
1 parent 3ea2ac8 commit 6f0d627
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion config/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package config

import (
"net/url"
"strings"

up "go.mau.fi/util/configupgrade"
Expand All @@ -30,7 +31,18 @@ func DoUpgrade(helper *up.Helper) {
legacyDB, ok := helper.Get(up.Str, "appservice", "database")
if ok {
if strings.HasPrefix(legacyDB, "postgres") {
helper.Set(up.Str, legacyDB, "appservice", "database", "uri")
parsedDB, err := url.Parse(legacyDB)
if err != nil {
panic(err)
}
q := parsedDB.Query()
if parsedDB.Host == "" && !q.Has("host") {
q.Set("host", "/var/run/postgresql")
} else if !q.Has("sslmode") {
q.Set("sslmode", "disable")
}
parsedDB.RawQuery = q.Encode()
helper.Set(up.Str, parsedDB.String(), "appservice", "database", "uri")
helper.Set(up.Str, "postgres", "appservice", "database", "type")
} else {
dbPath := strings.TrimPrefix(strings.TrimPrefix(legacyDB, "sqlite:"), "///")
Expand Down

0 comments on commit 6f0d627

Please sign in to comment.