fireproofsocks

fireproofsocks

Running all migrations in all children apps from root of umbrella app

I’m working on an umbrella app that has a dozen or so children apps. I really like how the the base config.exs has a simple line that tells the umbrella to load up all of the children’s configs:

import_config "../apps/*/config/config.exs"

I’m wondering how to implement something like that for the various ecto commands, e.g. ecto.migrate ? I would prefer to not have to cd into each app and run migrations separately.

Does someone have an elegant solution for this? Thanks!

Most Liked

axelson

axelson

Scenic Core Team

I work on an umbrella app and we have a workable solution (I wouldn’t call it elegant). We use it mainly for helping us run the migrations in the test env but you can easily expand it to general migrations.

mix.exs (root):

  defp aliases do
    [
      "test.setup": [
        "cmd MIX_ENV=test mix test.setup"
      ],
    ]
  end

apps/app_one/mix.exs:

  defp aliases do
    [
      "test.setup": ["ecto.create --quiet", "ecto.migrate"]
    ]
  end

apps/app_two/mix.exs:

  defp aliases do
    [
      "test.setup": ["ecto.create --quiet", "ecto.load"]
    ]
  end

apps/app_three/mix.exs:

  defp aliases do
    [
      "test.setup": []
    ]
  end

These are three “types” of different test database setups that we have. Note that the cmd in the root (see mix help cmd) is key here since it is what is cd’ing into each directory for you.

Some warnings:

  • If you run this command before compiling your project you will compile each project with an incomplete set of dependencies and any of your dependencies has code like if Code.ensure_loaded?(Phoenix) do defmodule end then Phoenix may not be detected as not loaded
  • If you don’t use mix cmd (transparently in this case) then the alias in one umbrella project will override the aliases in another project (since the configuration is shared)
fireproofsocks

fireproofsocks

Interesting. I’m wondering if we could get by with simply enumerating all the necessary seed files in the mix.exs alias. Something like:

defp aliases do
    [
      "ecto.setup": ["ecto.create", "ecto.migrate", 
        "run apps/app_one/priv/repo/seeds.exs",
        "run apps/app_two/priv/repo/seeds.exs",
        "run apps/app_three/priv/repo/seeds.exs",
        # ...
      ],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
    ]
end

That seems like it might work in our case…

Adzz

Adzz

fwiw I just used a Makefile, bit of a hack, but then you can at least automate cd’ing into each app and doing what you need.

Where Next?

Popular in Questions Top

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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement