commanded / eventstore

Event store using PostgreSQL for persistence
MIT License
1.06k stars 146 forks source link

fix: merge session mode pool config with main config, preserving options #293

Open gf3 opened 1 month ago

gf3 commented 1 month ago

When providing a session mode pool config via session_mode_url, it's not clear that session_mode_url is parsed into a keyword list and replaces the parent config.

For example, we use the following configuration to connect to Digital Ocean's managed Postgres:

config :our_app, OurApp.EventStore,
  default_database: "defaultdb",
  serializer: Commanded.Serialization.JsonSerializer,
  url: event_store_database_url,
  session_mode_url: event_store_session_database_url,
  ssl: true,
  ssl_opts: [cacertfile: ~c"/etc/ssl/certs/db.ca-certificate.crt", verify: :verify_peer],
  prepare: :unnamed,
  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
  socket_options: maybe_ipv6

The options ssl, ssl_opts, and prepare are particularly important to our connection and are not included when generating the config (session mode pool config) from the session_mode_url.

This PR merges the session mode pool config into the parent config before passing it along. So that all the specified configuration options are used for the session mode pool, too. Which, I think, is what people probably expect when looking at the above event store configuration.