Skip to content

Commit 6dd7df5

Browse files
authored
Fix rollback failure removing reference MySQL (#497)
Closes #494
1 parent 372c5c4 commit 6dd7df5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/ecto/migration/runner.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ defmodule Ecto.Migration.Runner do
267267
table_reverse(t, [{:modify, name, reverse_type, reverse_opts} | acc])
268268
end
269269
end
270-
defp table_reverse([{:add, name, _type, _opts} | t], acc) do
271-
table_reverse(t, [{:remove, name} | acc])
270+
defp table_reverse([{:add, name, type, _opts} | t], acc) do
271+
table_reverse(t, [{:remove, name, type, []} | acc])
272272
end
273273
defp table_reverse([_ | _], _acc) do
274274
false

test/ecto/migration_test.exs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ defmodule Ecto.MigrationTest do
773773
{:modify, :title, :text, [from: {:string, null: false, size: 100}, null: true, size: 255]},
774774
{:modify, :author, :text, [from: :string, null: false]},
775775
{:modify, :extension, :string, from: :text},
776-
{:remove, :summary}
776+
{:remove, :summary, :text, []}
777777
]}
778778

779779
assert_raise Ecto.MigrationError, ~r/cannot reverse migration command/, fn ->
@@ -882,5 +882,16 @@ defmodule Ecto.MigrationTest do
882882
end
883883
end
884884

885+
test "backward: adding a reference column (column type is returned)" do
886+
alter table(:posts) do
887+
add :author_id, references(:authors)
888+
end
889+
890+
flush()
891+
892+
assert {:alter, %Table{name: "posts"},
893+
[{:remove, :author_id, %Reference{table: "authors"}, []}]} = last_command()
894+
end
895+
885896
defp last_command(), do: Process.get(:last_command)
886897
end

0 commit comments

Comments
 (0)