Created
May 23, 2017 23:44
-
-
Save yeongsheng-tan/a531b7d8d7d46a65587b7674b7eb5fbd to your computer and use it in GitHub Desktop.
Example custom MFA for migration task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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