mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[fix] Make postgres connections magically work in common setups (#352)
* Don't use the system 'postgres' database by default * Use postgres adapter defaults The pgx code actually goes to great lengths to make postgres connections Just Work(tm) out of the box, including supporting `~/.pg_service.conf`, SSL certificates, UNIX sockets if it can find a socket at a common path, and falling back to TCP to localhost if not. (On Windows, it won't try to use UNIX sockets, but will read credentials from %appdata% as is standard over there.) By applying our flags as overrides only when they're specified, database connections should Just Work(tm) anywhere `psql gotosocial` does.
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user