How to use Postgres' enumerated type with Ecto

Maybe I did something wrong but I just created the type and field like this:

# creating the database type
execute("create type post_status as enum ('published', 'editing')")

# creating a table with the column
create table(:posts) do
  add :post_status, :post_status, null: false
end

and then just made the field a string:

field :post_status, :string

and it seems to work.


Small enhancement for @JustMichael. If you need to rollback, you can use:

def down do
  drop table(:posts)
  execute("drop type post_type")
end