summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/config/defaults.go8
-rw-r--r--internal/db/bundb/bundb.go40
2 files changed, 20 insertions, 28 deletions
diff --git a/internal/config/defaults.go b/internal/config/defaults.go
index 323e5d622..cf3e7b449 100644
--- a/internal/config/defaults.go
+++ b/internal/config/defaults.go
@@ -34,11 +34,11 @@ var Defaults = Values{
TrustedProxies: []string{"127.0.0.1/32"}, // localhost
DbType: "postgres",
- DbAddress: "localhost",
+ DbAddress: "",
DbPort: 5432,
- DbUser: "postgres",
- DbPassword: "postgres",
- DbDatabase: "postgres",
+ DbUser: "",
+ DbPassword: "",
+ DbDatabase: "gotosocial",
DbTLSMode: "disable",
DbTLSCACert: "",
diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go
index 19414b758..47fe4fb47 100644
--- a/internal/db/bundb/bundb.go
+++ b/internal/db/bundb/bundb.go
@@ -280,29 +280,11 @@ func deriveBunDBPGOptions() (*pgx.ConnConfig, error) {
return nil, fmt.Errorf("expected db type of %s but got %s", db.DBTypePostgres, viper.GetString(keys.DbType))
}
- // validate port
+ // these are all optional, the db adapter figures out defaults
port := viper.GetInt(keys.DbPort)
- if port == 0 {
- return nil, errors.New("no port set")
- }
-
- // validate address
address := viper.GetString(keys.DbAddress)
- if address == "" {
- return nil, errors.New("no address set")
- }
-
- // validate username
username := viper.GetString(keys.DbUser)
- if username == "" {
- return nil, errors.New("no user set")
- }
-
- // validate that there's a password
password := viper.GetString(keys.DbPassword)
- if password == "" {
- return nil, errors.New("no password set")
- }
// validate database
database := viper.GetString(keys.DbDatabase)
@@ -363,11 +345,21 @@ func deriveBunDBPGOptions() (*pgx.ConnConfig, error) {
}
cfg, _ := pgx.ParseConfig("")
- cfg.Host = address
- cfg.Port = uint16(port)
- cfg.User = username
- cfg.Password = password
- cfg.TLSConfig = tlsConfig
+ if address != "" {
+ cfg.Host = address
+ }
+ if port > 0 {
+ cfg.Port = uint16(port)
+ }
+ if username != "" {
+ cfg.User = username
+ }
+ if password != "" {
+ cfg.Password = password
+ }
+ if tlsConfig != nil {
+ cfg.TLSConfig = tlsConfig
+ }
cfg.Database = database
cfg.PreferSimpleProtocol = true
cfg.RuntimeParams["application_name"] = viper.GetString(keys.ApplicationName)