tanweerdev
How to run migrations of another app from main app
I am following umbrella apps structure in my project. and I am writing access layer app which doesn’t have separate repo but requires to have certain tables and relations migrated for it to work. I dont wanna create separate repo for it and make it complex to maintain configs etc.
I have tried following two approaches
defmodule Data.Repo.Migrations.CreateActions do
use Ecto.Migration
def change do
# First approach
opts = []
file_path = ExAcl.SeedHelper.priv_path_for("20181129092126_create_actions.exs", app: :acl)
Ecto.Migrator.run(Data.Repo, file_path, :up, opts)
{:ok, _} = Application.ensure_all_started(:acl)
# Second approach
Ecto.Migrator.up(HaiData.Repo, 20181129092126, ExAcl.Repo.Migrations.CreateActions)
end
end
But It doesn’t run migrations in another app.
Maybe I am not going in right direction. I am not sure what is the best way to run migration in another app
Goal: run migrations in acl app via main data app.
Most Liked
josevalim
Actually, what controls which migrations run is the :ecto_repos configuration option inside your application. So you can always do this:
config :my_app, :ecto_repos, [MyApp.Repo, OtherApp.Repo]
If you don’t want that to always happen though, you can always pass the repository to the migrate command:
$ mix ecto.migrate --repo OtherApp.Repo
And using the lower level APIs, such as Ecto.Migrator, should work too!
NobbZ
And still, each repo searches in its own application. The OP though wants a single repo with migrations in 2 applications.
josevalim
Ah, I misunderstood. Thanks for clarifying.
The only way this can be achieved then is by calling mix ecto.migrate --migration-path "/path/to/another/path". So you would have to call it twice.







