Skip to content

Commit

Permalink
Raise if target migration version is not an integer (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschiavon91 committed Nov 23, 2022
1 parent 392a85e commit 4371bb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ecto/migrator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ defmodule Ecto.Migrator do
lock_for_migrations(lock, repo, opts, fun)
end

defp pending_to(versions, migration_source, direction, target) do
defp pending_to(versions, migration_source, direction, target) when is_integer(target) do
within_target_version? = fn
{version, _, _}, target, :up ->
version <= target
Expand All @@ -549,7 +549,7 @@ defmodule Ecto.Migrator do
|> Enum.take_while(&(within_target_version?.(&1, target, direction)))
end

defp pending_to_exclusive(versions, migration_source, direction, target) do
defp pending_to_exclusive(versions, migration_source, direction, target) when is_integer(target) do
within_target_version? = fn
{version, _, _}, target, :up ->
version < target
Expand Down
14 changes: 14 additions & 0 deletions test/ecto/migrator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,20 @@ defmodule Ecto.MigratorTest do
assert run(TestRepo, paths, :up, to: 12, log: false) == [10, 11, 12]
end)
end

test "raises if target is not integer" do
in_tmp fn path ->
message_base = "no function clause matching in "

assert_raise(FunctionClauseError, message_base <> "Ecto.Migrator.pending_to/4", fn ->
run(TestRepo, path, :up, to: "123")
end)

assert_raise(FunctionClauseError, message_base <> "Ecto.Migrator.pending_to_exclusive/4", fn ->
run(TestRepo, path, :up, to_exclusive: "123")
end)
end
end
end

describe "migrations" do
Expand Down

0 comments on commit 4371bb7

Please sign in to comment.