We have an application that we use to access a PostGres database using Ecto – let’s refer to it as the SharedDb
app. This SharedDb
application doesn’t do much on its own – usually other applications list it as a dependency and the other applications put it into their own supervision trees.
However, I noticed a problem when I started to write tests for this SharedDb
app: it doesn’t start up the Ecto Repo – so I can’t actually test any database inserts. My question is:
Is it possible to start up the Ecto Repo process only in the test environment?
I did something like this for a similar app a while ago:
defmodule SharedDb.Application do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [supervisor(SharedDb.Repo, [])]
opts = [strategy: :one_for_one, name: SharedDb.Supervisor]
Supervisor.start_link(children, opts)
end
end
but in our case, we explicitly require that the other apps supervise this one.
I am not an expert with any of the supervision / process stuff, so any guidance here is much appreciated. Thanks!