We're a place where coders share, stay up-to-date and grow their careers.
That Mix.env() is one way to achieve that. Personally I would still use String.replace/3, since Elixir 1.9 introduced a new way to configure your application without Mix dependency in your config-files.
Mix.env()
String.replace/3
I would do it this way:
test.exs
database_url = System.get_env("DATABASE_URL") config :myapp, Myapp.Repo, url: String.replace(database_url, "?", "test"), pool: Ecto.Adapters.SQL.Sandbox
.env
DATABASE_URL=postgres://postgres:postgres@db:5432/myapp__?
That
Mix.env()
is one way to achieve that. Personally I would still useString.replace/3
, since Elixir 1.9 introduced a new way to configure your application without Mix dependency in your config-files.I would do it this way:
test.exs
.env