zoedsoupe

zoedsoupe

How I can reorder migrations execution in umbrella apps?

I created an umbrella app as a template for a workshop I’ll give into my university. So I preferred to show an umbrella project to build many APIs projects that communicate between them. So each app has it own Ecto.Repo and also its migrations path/files.

However it seems that migrations are runned in the order of app creation/disposition on the apps directory.

This is the current structure of my apps:

.
├── Dockerfile
├── README.md
├── apps
│   ├── liquid_accounts
│   ├── liquid_auth
│   ├── liquid_operations
│   ├── proxy_web
│   └── release
├── config
│   ├── config.exs
│   ├── dev.exs
│   ├── prod.exs
│   ├── runtime.exs
│   └── test.exs
├── docker-compose.yml
├── flake.lock
├── flake.nix
├── mix.exs
├── mix.lock
└── rel

When I trying to run migrations (2 from liquid_auth and 1 for liquid_accounts), that occurs:

The database for Liquid.Accounts.Repo has been dropped
The database for Liquid.Auth.Repo has already been dropped
The database for Liquid.Operations.Repo has already been dropped
The database for Liquid.Accounts.Repo has been created
The database for Liquid.Auth.Repo has already been created
The database for Liquid.Operations.Repo has already been created

21:24:25.695 [info] == Running 20231020225840 Liquid.Accounts.Repo.Migrations.CreateBankAccount.change/0 forward

21:24:25.697 [info] create table bank_account
** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "user" does not exist
    (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1047: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (ecto_sql 3.10.2) lib/ecto/adapters/sql.ex:1154: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.10.2) lib/ecto/migration/runner.ex:327: Ecto.Migration.Runner.log_and_execute_ddl/3
    (elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (ecto_sql 3.10.2) lib/ecto/migration/runner.ex:290: Ecto.Migration.Runner.perform_operation/3
    (stdlib 5.1.1) timer.erl:270: :timer.tc/2
    (ecto_sql 3.10.2) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8

Of course relation “user” doesn’t exist! It is defined on liquid_auth app, which it should be the first one migrated as those migrations were the first ones I created…

Migrations of liquid_auth:

20231020160450_create_user.exs		20231020173651_create_api_key.exs

And the only migration for liquid_accounts: 20231020225840_create_bank_account.exs.

So how can I reorder the migrations execution order?

Most Liked

LostKobrakai

LostKobrakai

I‘d argue that a single db should be handled by a single set of migrations. And if you don‘t follow that advice then you want to avoid dependencies between the separate systems. That can be done e.g. using namespacing of global things like tables.

One could argue that migrations should run in order of the dependency tree between the applications, but not sure if ecto does/could have access to that.

Edit: Maybe you can already customize the oder with the ecto_repos configuration.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
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
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement