When create_type/0 was made to be reversible, it removed the ability to do a migration where you drop the type on the way up and recreate it on the way down.
Example:
defmodule Migration do
use Ecto.Migration
def up do
SampleEnum.drop_type()
end
def down do
SampleEnum.create_type()
end
end
This is because when rolling back, create_type/0 tries to run the DROP SQL when in reality we want the CREATE SQL.
One fix, perhaps is to just make drop_type/0 reversible as well. Then you'd call drop_type/0 in both up/down and it should work.
Another fix would be to change the API so that create_type/0 and drop_type/0 do what they say on the tin, and introduce a different function, e.g. migrate/0, that does a reversible action.
TL;DR it's impossible to recreate the enum type in a drop migration.
When
create_type/0
was made to be reversible, it removed the ability to do a migration where you drop the type on the way up and recreate it on the way down.Example:
This throws an error:
This is because when rolling back,
create_type/0
tries to run the DROP SQL when in reality we want the CREATE SQL.One fix, perhaps is to just make
drop_type/0
reversible as well. Then you'd calldrop_type/0
in bothup
/down
and it should work.Another fix would be to change the API so that
create_type/0
anddrop_type/0
do what they say on the tin, and introduce a different function, e.g.migrate/0
, that does a reversible action.TL;DR it's impossible to recreate the enum type in a drop migration.