Perhaps the Ecto.Repo.init/2-callback can help you?
Ecto.Repo.init/2
A short example of how to use it, can be seen in this post: