mattfara50

mattfara50

Ecto schemas in a project that is depended upon by multiple projects

I have a situation at work where two distinct Phoenix projects, A and B, duplicate the same schemas, since they truck in the same db tables. This is painful, since migrations must be done twice. My instinct is to make a sort of library project, C, which A and B would call as file dependencies. All the schemas would reside there. I understand that this might not be conventional, or that it would also be possible to merge the A and B into one (much) larger project, but I’m wondering if this dependency model is even possible. If so, what would you call out as drawbacks? What would you call out as benefits? I should say that I’m a rank beginner. Please simplify.

Marked As Solved

7rans

7rans

  1. Correct. And that was a major motivation for this approach.

  2. Yes.

  3. It SoC’d the rest well too. Everything related to that database was test in C. C gets involved in tests for A (and B) but indirectly (integration testing basically).

  4. Some people/organizations like monorepos but I tend to find clean separations easier on my mind. It’s important that they are clean separations though! C should straightforward and general.

  5. Hmm… I don’t think it’s too much of an issue. I use a git dependency in A/B’s mix.exs. So that pulls it in just fine.

  6. A little but not much. Again with a clear separation, C doesn’t change much once built out.

  7. No defdelegate. I kept it very simple. C is almost all schema code, and some very general reusable queries. Not much else.

I think the question to ask is how strongly tied they are. If C could be useful for more then just A and/or B (at least hypothetically) then it probably makes sense.

Also Liked

7rans

7rans

I did exactly this and it does work.

But there is a BIG gotcha you have look out for. If you create a database repo in project C (which you probably will for testing and development), when you include project C in your dependencies for A or B its going to automatically try to connect with the database when you run A or B. (I don’t 100% know why, but it does.) I didn’t realize this and had setup a separate connection with the database in my “project A”. And I kept getting an error about a missing socket (even though I was using tcp) – it was Project C’s repo trying to talk to the database but hadn’t been fully configured.

The solution was to utilize the repo from project C and not try to recreate it in A or B. There is probably a way to do otherwise but this worked for me. FYI you still have to config C’s repo in project A (and B). I also added it to A’s (or B’s) supervision tree (though maybe that wasn’t necessary?)

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New

Other popular topics Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement