Skip to content

Instantly share code, notes, and snippets.

@bydooweedoo
Forked from alanpeabody/A_README.md
Created August 9, 2017 07:08
Show Gist options
  • Save bydooweedoo/8befe5ca1712966cfb437dca875103b6 to your computer and use it in GitHub Desktop.
Save bydooweedoo/8befe5ca1712966cfb437dca875103b6 to your computer and use it in GitHub Desktop.
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