Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jclosure/863d64f2541f57c20c7d6b7e900ba44e to your computer and use it in GitHub Desktop.
Save jclosure/863d64f2541f57c20c7d6b7e900ba44e to your computer and use it in GitHub Desktop.
How to run Ecto migrations in Elixir/Phoenix from an `iex -S mix` or production console
# How to run Ecto migrations from IEx console... Examples
# preliminaries assumed in the following code, change to fit your environment:
alias YourAppName.Repo
your_app_name_as_atom = :mpnetwork
downto_version = 20170724182558
# Down:
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :down, [to: downto_version])
# Up:
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :up, [all: true])
# In production when not sure if working directory is inside app dir:
Ecto.Migrator.run(Repo, Application.app_dir(your_app_name_as_atom, "priv/repo/migrations"), :down, [to: downto_version])
Ecto.Migrator.run(Repo, Application.app_dir(your_app_name_as_atom, "priv/repo/migrations"), :up, [all: true])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment