Sharing Ecto Models Between Projects

Hello, I have two different projects, one of them is elixir project, the second one is phoenix project, but they are use one database and models in that db.
Problem is that if I changing something in db table, I need to change both of model files on both of projects, maybe I can somehow create a file and after import it to my models files?

In such a case it’s probably best to have an additional elixir app both of your current ones can depend on. Then you need to change anything related to the db only in one place.

1 Like

So i have this problem with Nerves based projects often.

I’ll build a phoenix app with a resource and the nerves app should GET/download the resource. I’ve tried this a number of different ways. To expand on what @LostKobrakai said heres an example with Nerves and Phoenix, but it isnt limited to just that:

  • my_project_core - has all the models/ecto stuff
  • my_project_web - phoenix app. Depends on my_project_core
  • my_project_fw - nerves app. Depends on my_project_core

if you have two projects using the same database this is probably the best way to go.

I don’t know if this is an option, but keep in mind you only need model/schema for the fields actually being used in each segment of the app. The problem you are describing is usually amplified when trying to fully include the schema on each one.

It might not be a fit for your use case, but something to keep in mind. If one side only needs a few fields it might not need every update.

1 Like