Mix.exs in umbrella app

I’m trying to make life simpler for our developers of an umbrella app. I was really excited when I discovered the mix cmd option. I have tried to update my aliases to achieve a unified control over migrations, seeding, and testing… I have ended up with something like this:

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",
        # ... etc...
      ],
      "ecto.create": ["cmd --app app_one --app app_two mix ecto.create"],
      "ecto.drop": ["cmd --app app_one --app app_two mix ecto.drop"],
      "ecto.migrate": ["cmd --app app_one --app app_two mix ecto.migrate"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
      coverage: ["MIX_ENV=test mix coveralls"]
    ]
end

However, I’ve noticed some odd behavior. mix ecto.drop, mix ecto.create, and mix ecto.migrate all work, but the aliases that reference other aliases are more problematic. If I try to run mix ecto.reset, the specific application databases are dropped, and right when I would expect them to be created, I get bombarded with a bunch of Postgrex errors:

[error] Postgrex.Protocol (#PID<0.381.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "app_one_dev" does not exist

none of the migrations run (or even try to run), then it jumps right into seeding, and that all fails because the databases don’t exist.

Can someone shed some light on what is going on? Thanks in advance!

1 Like