Skip to content

Instantly share code, notes, and snippets.

@navinpeiris
Created February 22, 2026 06:48
Show Gist options
  • Select an option

  • Save navinpeiris/d9b011fe39c90b919fce71f7085cb74d to your computer and use it in GitHub Desktop.

Select an option

Save navinpeiris/d9b011fe39c90b919fce71f7085cb74d to your computer and use it in GitHub Desktop.
test.exs config for branch specific db's
git_branch =
case System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]) do
{branch, 0} -> String.trim(branch)
_ -> ""
end
db_suffix =
if git_branch == "main" do
""
else
"_#{git_branch}"
|> String.replace("/", "_")
|> String.replace("-", "_")
|> String.downcase()
end
db_suffix = "#{db_suffix}#{System.get_env("MIX_TEST_PARTITION")}"
config :xyz, Xyz.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "xyz_test#{db_suffix}",
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: System.schedulers_online() * 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment