gjaldon / ecto_enum

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

Use with Postgres Enum Type #14

Closed zimt28 closed 8 years ago

zimt28 commented 8 years ago

Does it make sense to use EctoEnum with the Postgres Enum Type? I think it's always a good idea to have things in the database as well. I'll try the following later, it would be nice if EctoEnum would provide a simple way to add the type to migrations as well.

def up do
  execute "CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')"

  create table(:persons) do
    add :current_mood, :mood
  end
end

def down do
  execute "DROP TYPE mood"

  drop table(:persons)
end

According to the Postgres docs, this would allow for cool things:

SELECT * FROM persons WHERE current_mood > 'sad';

Not sure though Ecto would support this.

Repo.all(from p in Persons, where: p.current_mood > "sad")
gjaldon commented 8 years ago

I think it does make sense. Someone else on the Elixir forum suggested this same thing too. I haven't really looked into how to implement this yet and if it is possible to implement this feature in an Ecto extension.

I'll look into it on my weekend. :) Feel free to look into it too. :)

gjaldon commented 8 years ago

@zimt28 latest release supports 0.4.0 supports Postgres's Enum Type! 😄