Connecting to a database from two different OTP apps in an umbrella

I have two apps, one is something like an interface, and the other is a webscraper. The interface app stores subscriptions of its users which are the names of files that the users want to get notifications on when the files are modified. The webscraper app stores these files’ names and digests. The files are constantly added so the interface app should be able to update the list of possible subscriptions.

Is there a way to tell ecto in the webscraper app to connect to the same database that the interface app is using, so that I would be able to create many_to_many relationship on users and files?


Sorry if I am misunderstanding your question, but I think you are already connecting to the same database, but you want to share the relationships, right? Sharing a DB is as simple as setting the config :app, Module.Repo to point to that DB.

However, in sharing relationships between two phoenix apps myself, I completely removed ecto from boths apps, and created a shared dependency with mix that contains all the models and relationship logic. This dependency is great, because I can easily test it, since there is no operations happening, just pure models and logic using Ecto.Changeset.


Wow, that’s clever. Somehow I didn’t think of that. Thanks a lot!


It took me about a week to realize this solution and build a proof of concept when I faced this problem, haha :smiley:

1 Like