diff --git a/lib/ecto/migrator.ex b/lib/ecto/migrator.ex index 38dfd1e1..1fc2fd1b 100644 --- a/lib/ecto/migrator.ex +++ b/lib/ecto/migrator.ex @@ -247,8 +247,6 @@ defmodule Ecto.Migrator do if version in versions do :already_up else - result = do_up(repo, config, version, module, opts) - if version != Enum.max([version | versions]) do latest = Enum.max(versions) @@ -271,7 +269,7 @@ defmodule Ecto.Migrator do end end - result + do_up(repo, config, version, module, opts) end end) end @@ -333,9 +331,14 @@ defmodule Ecto.Migrator do dynamic_repo = repo.get_dynamic_repo() fun_with_status = fn -> - result = fun.() - apply(SchemaMigration, direction, [repo, config, version, opts]) - result + case fun.() do + :ok -> + apply(SchemaMigration, direction, [repo, config, version, opts]) + :ok + + result -> + result + end end fn -> run_maybe_in_transaction(repo, dynamic_repo, module, fun_with_status, opts) end diff --git a/test/ecto/migrator_test.exs b/test/ecto/migrator_test.exs index 5c815ecb..39a583c7 100644 --- a/test/ecto/migrator_test.exs +++ b/test/ecto/migrator_test.exs @@ -396,6 +396,8 @@ defmodule Ecto.MigratorTest do assert_raise Ecto.MigrationError, fn -> up(TestRepo, 0, Migration, log: false, strict_version_order: true) end + + refute {0, nil} in MigrationsAgent.get() end test "up invokes the repository adapter with up commands" do @@ -418,12 +420,16 @@ defmodule Ecto.MigratorTest do assert_raise Ecto.MigrationError, fn -> Ecto.Migrator.up(TestRepo, 10, InvalidMigration, log: false) end + + refute {10, nil} in MigrationsAgent.get() end test "down raises error when missing down/0 and change/0" do assert_raise Ecto.MigrationError, fn -> Ecto.Migrator.down(TestRepo, 1, InvalidMigration, log: false) end + + assert {1, nil} in MigrationsAgent.get() end # TODO: Remove when we require Elixir 1.14