I am experimenting with an umbrella project that uses Phoenix to provide sockets and an API. I have separate apps for authentication, chat, and posts. This topic is similar to Should we Separate Ecto From Phoenix in Umbrella App?.
I am wondering if the following approach is a sane one (and for alternative recommendations if not).
- A db app that manages all migrations and is connected to an underlying database.
- The remaining apps and services each have their own Ecto repo that define schemas (including changesets). These will reference other App repos for foreign key relationships. Data validation and error handling would then be dealt with on a per app basis. The goal would be to hopefully limit the coupling of the apps to the schema definitions.
As a secondary question:
Initially, I attempted to create separate databases for each app. The preclusion of using foreign keys across databases makes this prohibitive. I briefly experimented with Postgres Foreign Data Wrappers, but it seems these are meant more for migration from older databases or short term use. Additionally, it seems too far from the norm for me to be comfortable pursuing at the moment and I am not sure how integration with Ecto (setting up foreign keys) would be. If anyone has any experience doing something similar, I would be curious.