How to use two databases (one local / one remote) for the same Phoenix application?

Not sharing data, different tables of each one. Is that possible?

1 Like

Of course it is possible. I would recommend creating an umbrella project, with separate applications holding RepoA and RepoB. Then you can put migrations into individual apps/repo_a or apps/repo_b subdirectories and have it neatly separated.

But you could also possibly set it up within one project, I didn’t try it however.

2 Likes

Actually, I want currently to store only authentication tokens in the server where the Phoenix application is hosted and the data on the remote server. I hope there is a library that makes connecting to additional databases easier.

1 Like

In ecto, the Repo module represents the database. There is nothing stopping you from having multiple modules that use Ecto.Repo - each connecting to a different database. There is no special library required, since ecto does not assume anywhere a “global” database connection.

9 Likes

Thank you very much. Cannot be simpler than that, I have already created a second DB and using it already.

3 Likes

In fact it does work. There is even a special -r switch to mix ecto.{functions} to specify which Repo to target.

3 Likes