Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/mix/tasks/ecto.migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ defmodule Mix.Tasks.Ecto.Migrations do
repo: [:keep, :string],
no_compile: :boolean,
no_deps_check: :boolean,
migrations_path: :keep
migrations_path: :keep,
prefix: :string
]

@moduledoc """
Expand Down Expand Up @@ -50,20 +51,22 @@ defmodule Mix.Tasks.Ecto.Migrations do

* `--no-deps-check` - does not check dependencies before running

* `--prefix` - the prefix to check migrations on

* `-r`, `--repo` - the repo to obtain the status for

"""

@impl true
def run(args, migrations \\ &Ecto.Migrator.migrations/2, puts \\ &IO.puts/1) do
def run(args, migrations \\ &Ecto.Migrator.migrations/3, puts \\ &IO.puts/1) do
repos = parse_repo(args)
{opts, _} = OptionParser.parse! args, strict: @switches, aliases: @aliases

for repo <- repos do
ensure_repo(repo, args)
paths = ensure_migrations_paths(repo, opts)

case Ecto.Migrator.with_repo(repo, &migrations.(&1, paths), [mode: :temporary]) do
case Ecto.Migrator.with_repo(repo, &migrations.(&1, paths, opts), [mode: :temporary]) do
{:ok, repo_status, _} ->
puts.(
"""
Expand Down
8 changes: 4 additions & 4 deletions test/mix/tasks/ecto.migrations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule Mix.Tasks.Ecto.MigrationsTest do
test "displays the up and down status for the default repo" do
Application.put_env(:ecto_sql, :ecto_repos, [Repo])

migrations = fn _, _ ->
migrations = fn _, _, _ ->
[
{:up, 0, "up_migration_0"},
{:up, 20160000000001, "up_migration_1"},
Expand Down Expand Up @@ -66,7 +66,7 @@ defmodule Mix.Tasks.Ecto.MigrationsTest do
end

test "migrations displays the up and down status for any given repo" do
migrations = fn _, _ ->
migrations = fn _, _, _ ->
[
{:up, 20160000000001, "up_migration_1"},
{:down, 20160000000002, "down_migration_1"}
Expand All @@ -89,7 +89,7 @@ defmodule Mix.Tasks.Ecto.MigrationsTest do
test "does not run from _build" do
Application.put_env(:ecto_sql, :ecto_repos, [Repo])

migrations = fn repo, [path] ->
migrations = fn repo, [path], _opts ->
assert repo == Repo
refute path =~ ~r/_build/
[]
Expand All @@ -105,7 +105,7 @@ defmodule Mix.Tasks.Ecto.MigrationsTest do
File.mkdir_p!(path2)

run ["-r", to_string(Repo), "--migrations-path", path1, "--migrations-path", path2],
fn Repo, [^path1, ^path2] -> [] end,
fn Repo, [^path1, ^path2], _opts -> [] end,
fn _ -> :ok end
end
end