Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Running a elixir dependency's migrations from parent app (in parent repo)

Goal

To pull in dependencies and have them run their migrations in the parent apps' repo.

Setup

MyChild - A mix application with ecto migrations, schemas, etc. MyParent - A phoenix application that wants to leverage the child application.

In this case MyParent has added MyChild as a mix dependency via github, eg:

{:my_child, github: "AgilionApps/my_child"}

# In Parent app
defmodule Mix.Tasks.Migrate do
use Mix.Task
@shortdoc "Run migrations for this project and dependencies"
def run(_) do
migrate_child_app
Mix.Task.run("ecto.migrate")
end
def migrate_child_app do
{:ok, _} = Application.ensure_all_started(:my_parent)
path = Application.app_dir(:my_child, "priv/repo/migrations")
Ecto.Migrator.run(MyParent.Repo, path, :up, all: true)
:init.stop()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment