How to update an ecto_enum that was used in a migration?

Let’s take the example from the README, and let’s say that I have a StatusEnum module with the following values:

[:registered, :active, :inactive, :archived, "registered", "active", "inactive", "archived"]

And then, I have a migration to add the status type to the users table:

def change do
  StatusEnum.create_type
  create table(:users_pg) do
    add :status, StatusEnum.type()
  end
end

Now, let’s say that I want to update the StatusEnum with a new value, for example :moderator , but I’ve already ran the migration and I don’t want to roll it back.

I know that I can easily add the value :moderator to the module where I defined StatusEnum , but what about the migration, especially since it was already ran?

If I remember correctly you need to write your own execute for that or alternatively (if possible) drop and recreate enum in new migration file.

Please take a look at the bottom of README.md as it shows an example execute call.

I’m working on more advanced library which would help in that and many more cases, but to finish it properly I would need some feedback (as I’m just not as much experienced in PostgreSQL/SQL as in Elixir) in case someone is interested. :slight_smile:

1 Like

Many thanks @Eiji!