Skip to content

Instantly share code, notes, and snippets.

@yeongsheng-tan
Created May 23, 2017 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeongsheng-tan/a531b7d8d7d46a65587b7674b7eb5fbd to your computer and use it in GitHub Desktop.
Save yeongsheng-tan/a531b7d8d7d46a65587b7674b7eb5fbd to your computer and use it in GitHub Desktop.
Example custom MFA for migration task
defmodule MyApp.ReleaseTasks do
@app :my_app
@start_apps [:postgrex, :ecto]
def migrate do
pre_start()
Enum.each([@app], &run_migrations_for/1)
post_start()
end
defp pre_start do
:ok = Application.load(@app)
IO.puts "Ensure app and dependencies are started."
Enum.each(@start_apps, &Application.ensure_all_started/1)
Enum.each([MyApp.Repo], &(&1.start_link(pool_size: 1)))
end
defp post_start do
IO.puts "Success!"
:init.stop()
end
defp priv_dir(app), do: "#{:code.priv_dir(app)}"
defp run_migrations_for(app) do
IO.puts "Running migrations for #{app}"
Ecto.Migrator.run(MyApp.Repo, migrations_path(app), :up, all: true)
end
defp migrations_path(app), do: Path.join([priv_dir(app), "repo", "migrations"])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment