Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reversible create_type/0 makes it impossible to drop type #109

Open
lleger opened this issue Jun 12, 2020 · 0 comments
Open

Reversible create_type/0 makes it impossible to drop type #109

lleger opened this issue Jun 12, 2020 · 0 comments

Comments

@lleger
Copy link

lleger commented Jun 12, 2020

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 throws an error:

$ mix ecto.migrate
# succeeds

$ mix ecto.rollback
** (Postgrex.Error) ERROR 42704 (undefined_object)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant