Skip to content

Commit 4371bb7

Browse files
authored
Raise if target migration version is not an integer (#460)
1 parent 392a85e commit 4371bb7

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/ecto/migrator.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ defmodule Ecto.Migrator do
537537
lock_for_migrations(lock, repo, opts, fun)
538538
end
539539

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

552-
defp pending_to_exclusive(versions, migration_source, direction, target) do
552+
defp pending_to_exclusive(versions, migration_source, direction, target) when is_integer(target) do
553553
within_target_version? = fn
554554
{version, _, _}, target, :up ->
555555
version < target

test/ecto/migrator_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,20 @@ defmodule Ecto.MigratorTest do
575575
assert run(TestRepo, paths, :up, to: 12, log: false) == [10, 11, 12]
576576
end)
577577
end
578+
579+
test "raises if target is not integer" do
580+
in_tmp fn path ->
581+
message_base = "no function clause matching in "
582+
583+
assert_raise(FunctionClauseError, message_base <> "Ecto.Migrator.pending_to/4", fn ->
584+
run(TestRepo, path, :up, to: "123")
585+
end)
586+
587+
assert_raise(FunctionClauseError, message_base <> "Ecto.Migrator.pending_to_exclusive/4", fn ->
588+
run(TestRepo, path, :up, to_exclusive: "123")
589+
end)
590+
end
591+
end
578592
end
579593

580594
describe "migrations" do

0 commit comments

Comments
 (0)