Skip to content

refactor: decouple config names and values #4157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

taimoorzaeem
Copy link
Collaborator

Decouples (or I should say "de-tuple" 🫤 ) the config names and values in config dumping. This opens up space for easier implementation of #4154. Not sure if that is the best way to refactor this. Would love any suggestions.

@taimoorzaeem taimoorzaeem marked this pull request as draft June 24, 2025 15:07
@steve-chavez
Copy link
Member

steve-chavez commented Jun 24, 2025

I think we do need a SSoT for the config names, but the refactor is not looking like a gain in maintenance (has more LOCs).

@taimoorzaeem As a shorter step towards #4154, how about first solving the duplication problem for the sample config in the CLI?

exampleConfigFile :: [Char]
exampleConfigFile =
[str|## Admin server used for checks. It's disabled by default unless a port is specified.
|# admin-server-port = 3001
|
|## The database role to use when no client authentication is provided
|# db-anon-role = "anon"
|
|## Notification channel for reloading the schema cache
|db-channel = "pgrst"
|
|## Enable or disable the notification channel
|db-channel-enabled = true
|
|## Enable in-database configuration
|db-config = true
|
|## Function for in-database configuration
|## db-pre-config = "postgrest.pre_config"
|
|## Extra schemas to add to the search_path of every request
|db-extra-search-path = "public"
|
|## Limit rows in response
|# db-max-rows = 1000
|
|## Allow getting the EXPLAIN plan through the `Accept: application/vnd.pgrst.plan` header
|# db-plan-enabled = false
|
|## Number of open connections in the pool
|db-pool = 10
|
|## Time in seconds to wait to acquire a slot from the connection pool
|# db-pool-acquisition-timeout = 10
|
|## Time in seconds after which to recycle pool connections
|# db-pool-max-lifetime = 1800
|
|## Time in seconds after which to recycle unused pool connections
|# db-pool-max-idletime = 30
|
|## Allow automatic database connection retrying
|# db-pool-automatic-recovery = true
|
|## Stored proc to exec immediately after auth
|# db-pre-request = "stored_proc_name"
|
|## Enable or disable prepared statements. disabling is only necessary when behind a connection pooler.
|## When disabled, statements will be parametrized but won't be prepared.
|db-prepared-statements = true
|
|## The name of which database schema to expose to REST clients
|db-schemas = "public"
|
|## How to terminate database transactions
|## Possible values are:
|## commit (default)
|## Transaction is always committed, this can not be overriden
|## commit-allow-override
|## Transaction is committed, but can be overriden with Prefer tx=rollback header
|## rollback
|## Transaction is always rolled back, this can not be overriden
|## rollback-allow-override
|## Transaction is rolled back, but can be overriden with Prefer tx=commit header
|db-tx-end = "commit"
|
|## The standard connection URI format, documented at
|## https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
|db-uri = "postgresql://"
|
|# jwt-aud = "your_audience_claim"
|
|## Jspath to the role claim key
|jwt-role-claim-key = ".role"
|
|## Choose a secret, JSON Web Key (or set) to enable JWT auth
|## (use "@filename" to load from separate file)
|# jwt-secret = "secret_with_at_least_32_characters"
|jwt-secret-is-base64 = false
|
|## Enables JWT Cache and sets its max size, disables caching with 0
|# jwt-cache-max-entries = 0
|
|## Logging level, the admitted values are: crit, error, warn, info and debug.
|log-level = "error"
|
|## Log the requested SQL query at the current log-level.
|log-query = "disabled"
|
|## Determine if the OpenAPI output should follow or ignore role privileges or be disabled entirely.
|## Admitted values: follow-privileges, ignore-privileges, disabled
|openapi-mode = "follow-privileges"
|
|## Base url for the OpenAPI output
|openapi-server-proxy-uri = ""
|
|## Configurable CORS origins
|# server-cors-allowed-origins = ""
|
|server-host = "!4"
|server-port = 3000
|
|## Allow getting the request-response timing information through the `Server-Timing` header
|server-timing-enabled = false
|
|## Unix socket location
|## if specified it takes precedence over server-port
|# server-unix-socket = "/tmp/pgrst.sock"
|
|## Unix socket file mode
|## When none is provided, 660 is applied by default
|# server-unix-socket-mode = "660"
|]

Then the benefit of the refactor will be clear.

@taimoorzaeem
Copy link
Collaborator Author

|## Function for in-database configuration
|## db-pre-config = "postgrest.pre_config"
|
|## Extra schemas to add to the search_path of every request
|db-extra-search-path = "public"
|
|## Limit rows in response
|# db-max-rows = 1000
|

The description before each config is understandable but can we afford to lose this trailing ## and # just before in each config here for instance, in db-pre-config and db-max-rows? Not sure what the means TBH.

My idea is to utilize Config.toText and intercalate with the description list. Just these trailing ## and # get in the way.

@steve-chavez
Copy link
Member

IIRC # db-max-rows = 1000 has the # because it's actually not set, there's no default. The configs that don't have a # prefix have a default like db-schemas = "public".

So the above means that there's an additional field for a type (that has possible values: default or empty), that would translate to those commented out configs.

I guess we put ## in the description for some tools (like vim) that automatically un-comment by removing one #, so the config remains valid.

It would be just a nicety to keep them as is.

@laurenceisla
Copy link
Member

laurenceisla commented Jun 27, 2025

IIRC # db-max-rows = 1000 has the # because it's actually not set, there's no default.

Agree, these are the ones labeled as "Default: n/a" in the docs (or in the case above when: default = not set). Note that this doesn't seem to be consistent right now, cause there are configs that are commented when they have a default value (like the db-pool... examples), so they shouldn't be commented anymore. I think these are specified as Maybe types in the AppConfig, so that could be a way to detect them programmatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants