Ecto - central repo for many releases/applications - migrations / API?

Hi!

I would like to ask for some general guidance. I have an app (let’s call it “DB”) which is bundled in its own release. Then I have “around the infrastructure” a bunch of other code bases/releases on its own. There is a purpose for that. Many of them are Umbrella based releases… and let’s assume they all need to access this Repo (Ecto, Postgres). This is like our Inventory and it should be a single source of truth. So migrations would be done only on this DB release.

But then when things live for longer time … and changes are done… what would be the best approach to avoid crashing other systems on migration change on this DB. Should everything be “wrapped” around some versioned API on this DB system?

But then I am not really sure, how this would work since I guess it would only work when adding fields to DB

I would really appreciate some guidance and general best practice suggestions

Best,
Tomaz

Not sure if that’s what you’re asking for, but if you include this DB app in your dependencies in other apps, you would have access to its structs. So whenever a struct changes in DB but you are using an older version of it in your other apps, the compiler would emit an error.

Like, if you had this schema before any changes

defmodule DB.User do
  use DB, :schema

  schema "users" do
    field(:first_name, :string)
    field(:last_name, :string)
  end
end

and used it somewhere else

defmodule OtherApp do
  def handle(%DB.User{first_name: first_name, last_name: last_name}) do
    # ...
  end
end

then changing the user schema to

defmodule DB.User do
  use DB, :schema

  schema "users" do
    field(:display_name, :string)
    field(:full_name, :string)
  end
end

would make OtherApp fail to compile. So you would avoid “crashing” at runtime by “crashing” at compile time.

Sorry, if that’s not relevant to what you’ve asked. Another way would be to create “versioned” deployments. Where clusters would be made out of nodes with the same version. So that when you deploy a new DB app, you change the cluster version, and only the nodes with the same version could be able to connect to it and use it.