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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









