Skip to content

Commit

Permalink
change name from db-url to db-postgres-connection-string
Browse files Browse the repository at this point in the history
  • Loading branch information
winston0410 committed Aug 8, 2024
1 parent 23aa7a9 commit 9d5d1e8
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
20 changes: 10 additions & 10 deletions docs/configuration/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ grant all privileges on database gotosocial to gotosocial;

GoToSocial makes use of ULIDs (Universally Unique Lexicographically Sortable Identifiers) which will not work in non-English collate environments. For this reason it is important to create the database with `C.UTF-8` locale. To do that on systems which were already initialized with non-C locale, `template0` pristine database template must be used.

If you want to use specific options when connecting to Postgres, you can use `db-url` to define the connection string. If `db-url` is defined, all other database related configuration fields will be ignored. For example, we can use `db-url` to connect to `mySchema`, where the user name is `myUser` and password is `myPass` at `localhost` with the database name of `db`:
If you want to use specific options when connecting to Postgres, you can use `db-postgres-connection-string` to define the connection string. If `db-postgres-connection-string` is defined, all other database related configuration fields will be ignored. For example, we can use `db-postgres-connection-string` to connect to `mySchema`, where the user name is `myUser` and password is `myPass` at `localhost` with the database name of `db`:

```yaml
db-url: 'postgres://myUser:myPass@localhost/db?search_path=mySchema'
db-postgres-connection-string: 'postgres://myUser:myPass@localhost/db?search_path=mySchema'
```
## Settings
Expand All @@ -67,14 +67,6 @@ db-url: 'postgres://myUser:myPass@localhost/db?search_path=mySchema'
# Default: "postgres"
db-type: "postgres"

# String. Full Database connection string
#
# This connection string is only applicable for Postgres. When this field is defined, all other database related configuration field will be ignored. This field allow you to fine tune connection with Postgres
#
# Examples: ["postgres://user:pass@localhost/db?search_path=gotosocial", "postgres://user:pass@localhost:9999/db"]
# Default: ""
db-url: ""

# String. Database address or parameters.
#
# For Postgres, this should be the address or socket at which the database can be reached.
Expand Down Expand Up @@ -191,6 +183,14 @@ db-sqlite-cache-size: "8MiB"
# Default: "30m"
db-sqlite-busy-timeout: "30m"

# String. Full Database connection string
#
# This connection string is only applicable for Postgres. When this field is defined, all other database related configuration field will be ignored. This field allow you to fine tune connection with Postgres
#
# Examples: ["postgres://user:pass@localhost/db?search_path=gotosocial", "postgres://user:pass@localhost:9999/db"]
# Default: ""
db-postgres-connection-string: ""

cache:
# cache.memory-target sets a target limit that
# the application will try to keep it's caches
Expand Down
16 changes: 8 additions & 8 deletions example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,6 @@ trusted-proxies:
# Default: "postgres"
db-type: "postgres"

# String. Full Database connection string
#
# This connection string is only applicable for Postgres. When this field is defined, all other database related configuration field will be ignored. This field allow you to fine tune connection with Postgres
#
# Examples: ["postgres://user:pass@localhost/db?search_path=gotosocial", "postgres://user:pass@localhost:9999/db"]
# Default: ""
db-url: ""

# String. Database address or parameters.
#
# For Postgres, this should be the address or socket at which the database can be reached.
Expand Down Expand Up @@ -256,6 +248,14 @@ db-sqlite-cache-size: "8MiB"
# Default: "30m"
db-sqlite-busy-timeout: "30m"

# String. Full Database connection string
#
# This connection string is only applicable for Postgres. When this field is defined, all other database related configuration field will be ignored. This field allow you to fine tune connection with Postgres
#
# Examples: ["postgres://user:pass@localhost/db?search_path=gotosocial", "postgres://user:pass@localhost:9999/db"]
# Default: ""
db-postgres-connection-string: ""

cache:
# cache.memory-target sets a target limit that
# the application will try to keep it's caches
Expand Down
28 changes: 14 additions & 14 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ type Configuration struct {
TrustedProxies []string `name:"trusted-proxies" usage:"Proxies to trust when parsing x-forwarded headers into real IPs."`
SoftwareVersion string `name:"software-version" usage:""`

DbURL string `name:"db-url" usage:"Full Database URL for connection to database"`
DbType string `name:"db-type" usage:"Database type: eg., postgres"`
DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"`
DbPort int `name:"db-port" usage:"Database port"`
DbUser string `name:"db-user" usage:"Database username"`
DbPassword string `name:"db-password" usage:"Database password"`
DbDatabase string `name:"db-database" usage:"Database name"`
DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"`
DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"`
DbMaxOpenConnsMultiplier int `name:"db-max-open-conns-multiplier" usage:"Multiplier to use per cpu for max open database connections. 0 or less is normalized to 1."`
DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"`
DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"`
DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"`
DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"`
DbType string `name:"db-type" usage:"Database type: eg., postgres"`
DbAddress string `name:"db-address" usage:"Database ipv4 address, hostname, or filename"`
DbPort int `name:"db-port" usage:"Database port"`
DbUser string `name:"db-user" usage:"Database username"`
DbPassword string `name:"db-password" usage:"Database password"`
DbDatabase string `name:"db-database" usage:"Database name"`
DbTLSMode string `name:"db-tls-mode" usage:"Database tls mode"`
DbTLSCACert string `name:"db-tls-ca-cert" usage:"Path to CA cert for db tls connection"`
DbMaxOpenConnsMultiplier int `name:"db-max-open-conns-multiplier" usage:"Multiplier to use per cpu for max open database connections. 0 or less is normalized to 1."`
DbSqliteJournalMode string `name:"db-sqlite-journal-mode" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_journal_mode"`
DbSqliteSynchronous string `name:"db-sqlite-synchronous" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_synchronous"`
DbSqliteCacheSize bytesize.Size `name:"db-sqlite-cache-size" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_cache_size"`
DbSqliteBusyTimeout time.Duration `name:"db-sqlite-busy-timeout" usage:"Sqlite only: see https://www.sqlite.org/pragma.html#pragma_busy_timeout"`
DbPostgresConnectionString string `name:"db-postgres-connection-string" usage:"Full Database URL for connection to postgres"`

WebTemplateBaseDir string `name:"web-template-base-dir" usage:"Basedir for html templating files for rendering pages and composing emails."`
WebAssetBaseDir string `name:"web-asset-base-dir" usage:"Directory to serve static assets from, accessible at example.org/assets/"`
Expand Down
50 changes: 25 additions & 25 deletions internal/config/helpers.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,31 +375,6 @@ func GetSoftwareVersion() string { return global.GetSoftwareVersion() }
// SetSoftwareVersion safely sets the value for global configuration 'SoftwareVersion' field
func SetSoftwareVersion(v string) { global.SetSoftwareVersion(v) }

// GetDbURL safely fetches the Configuration value for state's 'DbURL' field
func (st *ConfigState) GetDbURL() (v string) {
st.mutex.RLock()
v = st.config.DbURL
st.mutex.RUnlock()
return
}

// SetDbURL safely sets the Configuration value for state's 'DbURL' field
func (st *ConfigState) SetDbURL(v string) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.DbURL = v
st.reloadToViper()
}

// DbURLFlag returns the flag name for the 'DbURL' field
func DbURLFlag() string { return "db-url" }

// GetDbURL safely fetches the value for global configuration 'DbURL' field
func GetDbURL() string { return global.GetDbURL() }

// SetDbURL safely sets the value for global configuration 'DbURL' field
func SetDbURL(v string) { global.SetDbURL(v) }

// GetDbType safely fetches the Configuration value for state's 'DbType' field
func (st *ConfigState) GetDbType() (v string) {
st.mutex.RLock()
Expand Down Expand Up @@ -725,6 +700,31 @@ func GetDbSqliteBusyTimeout() time.Duration { return global.GetDbSqliteBusyTimeo
// SetDbSqliteBusyTimeout safely sets the value for global configuration 'DbSqliteBusyTimeout' field
func SetDbSqliteBusyTimeout(v time.Duration) { global.SetDbSqliteBusyTimeout(v) }

// GetDbPostgresConnectionString safely fetches the Configuration value for state's 'DbPostgresConnectionString' field
func (st *ConfigState) GetDbPostgresConnectionString() (v string) {
st.mutex.RLock()
v = st.config.DbPostgresConnectionString
st.mutex.RUnlock()
return
}

// SetDbPostgresConnectionString safely sets the Configuration value for state's 'DbPostgresConnectionString' field
func (st *ConfigState) SetDbPostgresConnectionString(v string) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.DbPostgresConnectionString = v
st.reloadToViper()
}

// DbPostgresConnectionStringFlag returns the flag name for the 'DbPostgresConnectionString' field
func DbPostgresConnectionStringFlag() string { return "db-postgres-connection-string" }

// GetDbPostgresConnectionString safely fetches the value for global configuration 'DbPostgresConnectionString' field
func GetDbPostgresConnectionString() string { return global.GetDbPostgresConnectionString() }

// SetDbPostgresConnectionString safely sets the value for global configuration 'DbPostgresConnectionString' field
func SetDbPostgresConnectionString(v string) { global.SetDbPostgresConnectionString(v) }

// GetWebTemplateBaseDir safely fetches the Configuration value for state's 'WebTemplateBaseDir' field
func (st *ConfigState) GetWebTemplateBaseDir() (v string) {
st.mutex.RLock()
Expand Down
2 changes: 1 addition & 1 deletion internal/db/bundb/bundb.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func maxOpenConns() int {
// deriveBunDBPGOptions takes an application config and returns either a ready-to-use set of options
// with sensible defaults, or an error if it's not satisfied by the provided config.
func deriveBunDBPGOptions() (*pgx.ConnConfig, error) {
url := config.GetDbURL()
url := config.GetDbPostgresConnectionString()

// if database URL is defined, ignore other DB related configuration fields
if url != "" {
Expand Down
4 changes: 2 additions & 2 deletions test/envparsing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ EXPECT=$(cat << "EOF"
"db-max-open-conns-multiplier": 3,
"db-password": "hunter2",
"db-port": 6969,
"db-postgres-connection-string": "",
"db-sqlite-busy-timeout": 1000000000,
"db-sqlite-cache-size": 0,
"db-sqlite-journal-mode": "DELETE",
"db-sqlite-synchronous": "FULL",
"db-tls-ca-cert": "",
"db-tls-mode": "disable",
"db-type": "sqlite",
"db-url": "",
"db-user": "sex-haver",
"dry-run": true,
"email": "",
Expand Down Expand Up @@ -213,7 +213,7 @@ GTS_BIND_ADDRESS='127.0.0.1' \
GTS_PORT=6969 \
GTS_TRUSTED_PROXIES='127.0.0.1/32,docker.host.local' \
GTS_DB_TYPE='sqlite' \
GTS_DB_URL='' \
GTS_DB_POSTGRES_CONNECTION_STRING='' \
GTS_DB_ADDRESS=':memory:' \
GTS_DB_PORT=6969 \
GTS_DB_USER='sex-haver' \
Expand Down

0 comments on commit 9d5d1e8

Please sign in to comment.