Migrations are applied incorrectly with multiple repos

Hi all 👋, I’m working on a project that uses multiple Repos to avoid pool exhaustion. I ran into the issue described here on ElixirForum: 👉https://elixirforum.com/t/migrations-are-applied-incorrectly-in-all-repos/61082 The recommendation there was to use the new -r flag but I’m hitting a snag: ➜ mix ash.codegen -r DataPipelineCron.Repo --dev Compiling 2 files (.ex) Generated data_pipeline_cron app Getting extensions in current project... Running codegen for AshPostgres.DataLayer... ** (Mix) Could not invoke task "ash_postgres.generate_migrations": 1 error found! -r : Unknown option Looking at https://hexdocs.pm/ash_postgres/Mix.Tasks.AshPostgres.GenerateMigrations.html I see the the generator no longer accepts this flag. My question: 👉 What’s the proper way to use ash.codegen with multiple repos to avoid duplicate migrations? Thanks in advance 🙏
Elixir Programming Language Forum
Migrations are applied incorrectly in all repos
In my system I’m adding a second repo to connect. To do that I did the following changes: config/config.exs config :marketplace, Marketplace.ApRepo, username: "postgres", password: "postgres", hostname: "localhost", database: "ap_dev", port: 5432, show_sensitive_data_on_connection_error: true, pool_size: 10 lib/ap_repo.ex def...
7 Replies
ZachDaniel
ZachDaniel2mo ago
🤔 that issue doesn't reccomend using the -r flag for ash.codegen that is for mix ash.rollback whats the specific issue you're having just so we can confirm its the same?
DePIN Ninja
DePIN NinjaOP2mo ago
because it creates the same migration for the two repos it's trying to create some things twice and the migration fails
No description
DePIN Ninja
DePIN NinjaOP2mo ago
to create the new repo I basically copy pasted the one the generator gave me and changed the name, is this the proper way to have multiple repos with ash? here are the steps to repro my specific case: 1. Initialized the project: mix igniter.new data_pipeline_cron_poc --with phx.new --install ash,ash_phoenix --install ash_postgres,ash_oban --install oban_web --yes 2. Added new oban repo - copy pasted default repo. 3. migrated successfully: mix ecto.create && mix ash.codegen --dev && mix ash.migrate 4. added ash money: mix igniter.install ash_money 5. The step above generated the same migration to add ash money twice so running mix ash.migrate fails.
17:25:15.639 [info] execute "CREATE TYPE public.money_with_currency AS (currency_code varchar, amount numeric);"
** (Postgrex.Error) ERROR 42710 (duplicate_object) type "money_with_currency" already exists
17:25:15.639 [info] execute "CREATE TYPE public.money_with_currency AS (currency_code varchar, amount numeric);"
** (Postgrex.Error) ERROR 42710 (duplicate_object) type "money_with_currency" already exists
ZachDaniel
ZachDaniel2mo ago
Ah, yeah so you should run mix ash.migrate and other commands with -r well... 🤔 oh 🤔 please create a reproduction and open an issue 🙂
DePIN Ninja
DePIN NinjaOP2mo ago
I found that it doesn’t duplicate migrations for resources, only for extensions. If I remove the migration from the Oban repo and re-run codegen, it won’t recreate the extension migration, so it’s not blocking me 👍. I’d say it’s a low-priority issue as it happens only when adding new extensions with igniter — do you still want me to create a GitHub issue?
ZachDaniel
ZachDaniel2mo ago
Yes please 🙇‍♂️ and yeah that makes sense, we probably want some kind of migrate_extensions? false callback on the repo

Did you find this page helpful?