finds.dev← search

// the find

gjaldon/ecto_enum

★ 570 · Elixir · MIT · updated May 2024

Ecto extension to support enums in models

EctoEnum adds enum-backed fields to Ecto schemas, letting you store integers, strings, or Postgres native enum types while working with atoms in application code. It's for Elixir/Phoenix developers who want typed status/state fields instead of raw strings or magic integers scattered through queries.

Handles the genuinely annoying Postgres native enum migration problem — ALTER TYPE ADD VALUE can't run in a transaction, and the README documents the @disable_ddl_transaction workaround instead of leaving you to discover it in production. Reflection helpers (__enum_map__, __valid_values__, valid_value?) are handy for building select options or validating changesets without hardcoding the value list twice. Supports both MySQL and Postgres with separate test suites for each backend, so it's not a Postgres-only tool despite the Postgres-specific features getting most of the README space.

Ecto core added its own Ecto.Enum module years ago that covers the basic integer/string/atom mapping case without a dependency, so for new projects the main reason left to reach for this library is the Postgres native enum type support specifically. There's no supported way to remove or reorder a Postgres enum value once added — the README just says avoid it and links to a Stack Overflow workaround, which will bite anyone whose schema changes over time. Three different ways to define an enum (defenum/2, use EctoEnum, use EctoEnum.Postgres) is more API surface than the problem needs, and you have to read the whole README to know which one applies to your case. Last push was mid-2024 with Travis CI and inch-ci badges pointing at services that no longer really function, which doesn't inspire confidence about how actively it's watched.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →