Skip to content

Commit f096fa5

Browse files
authored
support --prefix option in ecto.migrations (#346)
1 parent fca6ada commit f096fa5

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Diff for: lib/mix/tasks/ecto.migrations.ex

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ defmodule Mix.Tasks.Ecto.Migrations do
1313
repo: [:keep, :string],
1414
no_compile: :boolean,
1515
no_deps_check: :boolean,
16-
migrations_path: :keep
16+
migrations_path: :keep,
17+
prefix: :string
1718
]
1819

1920
@moduledoc """
@@ -50,20 +51,22 @@ defmodule Mix.Tasks.Ecto.Migrations do
5051
5152
* `--no-deps-check` - does not check dependencies before running
5253
54+
* `--prefix` - the prefix to check migrations on
55+
5356
* `-r`, `--repo` - the repo to obtain the status for
5457
5558
"""
5659

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

6265
for repo <- repos do
6366
ensure_repo(repo, args)
6467
paths = ensure_migrations_paths(repo, opts)
6568

66-
case Ecto.Migrator.with_repo(repo, &migrations.(&1, paths), [mode: :temporary]) do
69+
case Ecto.Migrator.with_repo(repo, &migrations.(&1, paths, opts), [mode: :temporary]) do
6770
{:ok, repo_status, _} ->
6871
puts.(
6972
"""

Diff for: test/mix/tasks/ecto.migrations_test.exs

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ defmodule Mix.Tasks.Ecto.MigrationsTest do
3838
test "displays the up and down status for the default repo" do
3939
Application.put_env(:ecto_sql, :ecto_repos, [Repo])
4040

41-
migrations = fn _, _ ->
41+
migrations = fn _, _, _ ->
4242
[
4343
{:up, 0, "up_migration_0"},
4444
{:up, 20160000000001, "up_migration_1"},
@@ -66,7 +66,7 @@ defmodule Mix.Tasks.Ecto.MigrationsTest do
6666
end
6767

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

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

107107
run ["-r", to_string(Repo), "--migrations-path", path1, "--migrations-path", path2],
108-
fn Repo, [^path1, ^path2] -> [] end,
108+
fn Repo, [^path1, ^path2], _opts -> [] end,
109109
fn _ -> :ok end
110110
end
111111
end

0 commit comments

Comments
 (0)