So I am exploring Umbrella Apps to migrate a old application to have a better separation of concerns and of course I am trying to use the mix phx.gen tasks generators.
I am using Phoenix 1.4 and this version has the :context_app generator configuration options which work perfectly. But I have the following scenario:
I am trying to use the “test” application to host the context API. And I am trying to use the “db_service” application to use all the ecto stuff like schemas, etc.
So I have two questions:
- Should I separate the context from the schemas or
- Is there a proper command mix phx.gen.html [options] to do all this operation in one go
It is important to say that I can configure this scenario using the different command: mix phx.gen.html, mix phx.gen.context, mix phx.gen.schema but I still require some manual changes to make this work properly.
Thank you all for your feedback and suggestions.
If I understand what you are trying to accomplish, then I would say “most definitely yes”. The context represents a logical chunk of functionality in your application - something that your application knows how to do. Say your application was for tracking shipments, then your context would be about how do you represent a shipment, what kind of operations can you do on shipments etc.
Your schema sits at the edge of your application and is concerned with how the elements of the context are represented in one particular type of storage (that being stored in a database). It’s a separation of concerns issue; you’re trying to separate what a thing is, from how that thing happens to be stored. If you wanted to get rid of a database and use a flat-file, or hook your application up to a 3D printer that generated plastic slabs where the data is encoded as if chiseled in stone, then you wouldn’t need the schemas - but the main logic of your application, the contexts, should still be valid.
Thanks for your explanation and time.