Optional ecto repos

I am having 3 optional repos(not all the databases need to exist). if I am successfully able to connect to any of the repos(I will check all the repos), I need to query(if all the databases are succesfully connected then on all the database) and perform my action.

I have created repos.ex files and corresponding configs.
after that when I need to query, I would start the repo like this
{:ok, pid} = DataLayer.DevRepo.start_link(name: :atom)
Note: (I have tried name: nil as well)

and when I try to query something, following error
> DataLayer.DevRepo.all DataLayer.User

** (ArgumentError) argument error
(stdlib) :ets.lookup_element(Ecto.Registry, nil, 3)
(ecto) lib/ecto/registry.ex:18: Ecto.Registry.lookup/1
(ecto) lib/ecto/adapters/sql.ex:251: Ecto.Adapters.SQL.sql_call/6
(ecto) lib/ecto/adapters/sql.ex:426: Ecto.Adapters.SQL.execute_and_cache/7
(ecto) lib/ecto/repo/queryable.ex:133: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:37: Ecto.Repo.Queryable.all/4

Any help will be really appreciated. Thanks

ecto version 2.2.11

if I add these 3 repos directly to supervisor tree, I can query and perform other task. But the problem is one of the server may go down and credentials won’t work any time. I need to connect to these repos optionally

If you want to start repos dynamically, maybe Can ecto repos be started dynamically? would be helpful. I have linked an example sqlite project there as well.

1 Like