Make DATABASE_URL configurable for dev and test#40
Conversation
Allow overriding the hardcoded Postgres config in dev/test via the DATABASE_URL environment variable, mirroring the existing prod behavior. Existing config/dev.exs and config/test.exs defaults are preserved when the variable is unset. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Review: Make DATABASE_URL configurable for dev and testOverall this is a small, well-scoped change that mirrors the existing Potential issue: collision with the existing
|
…ool merge Callout the .env/compose.yml DATABASE_URL collision risk and the MIX_TEST_PARTITION caveat in the README, and add a test proving the compile-time pool_size/pool settings survive being merged with the DATABASE_URL runtime override. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Summary
dev/testvia theDATABASE_URLenvironment variable, mirroring the existingprodbehavior.config/dev.exs/config/test.exsdefaults are left completely untouched and remain in effect wheneverDATABASE_URLis unset.Implementation notes
config/runtime.exsalready runs for everyMixenv (dev/test/prod), so the new override is a small guarded block:if config_env() in [:dev, :test]+if database_url = System.get_env("DATABASE_URL"), settingconfig :bodhi, Bodhi.Repo, url: database_url.pool_size, the sandbox pool config, etc.test/config/runtime_test.exs, which re-evaluatesconfig/runtime.exsviaConfig.Reader.read!/2for:devand:test, asserting: no override whenDATABASE_URLis unset, and the URL is applied when it is set.Verification (see note below on sandbox limitations)
mix compile— no new warnings (one pre-existing, unrelated warning inlib/bodhi/tg_webhook_handler.expresent onmaintoo)test/config/runtime_test.exspass (4/4)mix runwith the new config in placemix dialyzer— passes with 0 errorsmix format— no changes neededmix credo --strict— no new issues (pre-existing issues only, in files untouched by this PR)mix testsuite — could not be run in this environment: the sandbox has no reachable Postgres instance (no Docker, no localpostgresbinary, no sudo to install one), somix ecto.createfails before any DB-backed test can run. This reproduces identically on unmodifiedmain, confirming it's a pre-existing environment limitation, not a regression from this change. Please run the full suite in CI/locally where Postgres is available.Test plan
mix testagainst the docker-compose Postgres service and confirms all DB-backed tests still passDATABASE_URLlocally fordev/testand confirm the app connects to the alternate databaseDATABASE_URLunset still connects to the existing default dev/test databases🤖 Generated with Claude Code