Ecto multiple repos-- how to ignore one for migrations

I have an app configured

config :my_app,
  ecto_repos: [MyApp.Repo, MyApp.LegacyRepo]

MyApp.Repo’s migrations are managed by Ecto. MyApp.LegacyRepo migrations are handled by Rails and error out on mix ecto.migrate

Is there a way to specify “I have two repos, but please ignore the second for migrations”?

2 Likes

Do you want to ignore them with mix ecto.migrate? Not sure how to do that, but in Ecto.Migrator.run/4 you need to pass a repo to run migrations for, so you can do it there, and it’s what usually gets suggested to be used with releases.

Oh, you can mix ecto.migrate -r Custom.Repo.

3 Likes

Thanks! This solves 80% of my issue.

I was able to update test/test_helper.rb in a phoenix app from

Mix.Task.run "ecto.migrate", ["--quiet"]

to

Mix.Task.run "ecto.migrate", ["-r", "MyApp.Repo", "--quiet"]

to get tests runs to just migrate the Repo I wanted, and not the other

3 Likes

I ran into this same question. It seems you can simply remove MyApp.LegacyRepo from ecto_repos in your config. It will still be usable in your codebase but it will not be used for migrations as that is what the ecto_repos key is mainly used for.

1 Like