I have an application which targets multiple databases, it's like an application that watch applications which make reports, mediate notifications, run tasks and stuffs, in a way that is impossible to be controlled statically(in the configuration file), so i thought that it could be done starting a supervisor that supervises multiple Repo
s just changing its settings in the opts
(i was thinking in a pool of repos, something like this, sounds crazy, i know), but it's impossible since Ecto.Repo
has a macro which makes connection bound to the Repo
's module, so, there's a way to rewrite the Ecto.Repo
in a way that i can achieve my needs? I looked at ecto's sources, but i've found no solution digging alone.
I also looked at this post, but there's a possibility that the application will target multiple instances, with different users, different credentials, etc.
I've reached some solutions using Code.eval
for create Repos on-the-fly, but i don't know how "good" is it, and if it's encouraged.
In case you know all the repositories you need to access I suggest splitting the application in more umbrella apps. Each umbrella app can connect to a different ecto repository.
As a good practice I always extract Ecto and database related code to separate umbrella applications separated by domains. You can see one example in this demo application: https://github.com/silviurosu/elixir-umbrella-ddd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With