Skip to content

Instantly share code, notes, and snippets.

@alanpeabody
Created July 17, 2016 15:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alanpeabody/f90dd93b4f00480bf90a66c637e89280 to your computer and use it in GitHub Desktop.
Save alanpeabody/f90dd93b4f00480bf90a66c637e89280 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