gjaldon / ecto_enum

Ecto extension to support enums in models
MIT License
563 stars 131 forks source link

Renaming enums #37

Closed lleger closed 7 years ago

lleger commented 7 years ago

In our app, we renamed a model and so the enum needed to be changed as well:

ModelName -> NewModelName ModelTypeEnum ->NewModelTypeEnum

Is there a good way to rename enums? Currently, we're creating a new enum definition entirely and migrating the PG columns manually.

gjaldon commented 7 years ago

That's how to do it currently. There're no helpers in EctoEnum for handling at the moment.

lleger commented 7 years ago

For reference in case someone comes here looking for an answer, here's how we did it with an Ecto migration:

defmodule MyApp.Repo.Migrations.ChangeFooEnumToBarEnum do
  use Ecto.Migration

  def up do
    execute("ALTER TYPE foo_enum RENAME TO bar_enum")
  end

  def down do
    execute("ALTER TYPE bar_enum RENAME TO foo_enum")
  end
end