Thanks for the tip about SchemaPlus::Enums, Nicholas. That definitely makes creating the enums nicer.
Unfortunately, I don't think that fixes the fact that a table that uses an enum as a column type can't be dumped into schema.rb. It ends up hitting this code that calls "valid_type?(type)" on the connection adapter: https://github.com/rails/rails/blob/2a71885a3f88562c57f81230d31518e5189c0dda/activerecord/lib/active_record/schema_dumper.rb#L145 Since the PostgreSQL adapter currently only considers native types to be "valid", tables using enums are not dumped: https://github.com/rails/rails/blob/c0d4aa2293db9d2a5c69a57920edcd4f43776e91/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L375-L377 I agree about the difficulties of having ActiveRecord::Enum use a native database enum, though I still think it would be nice. I'd settle for being able to do something with an "attribute" declaration instead and avoiding "enum", since I don't generally use the helper methods that "enum" generates. -md On Monday, May 23, 2016 at 5:35:32 AM UTC-7, Nicholas Firth-McCoy wrote: > > I'm definitely interested in this. > > If you just want to be able to create enums in an > `ActiveRecord::Migration`, the SchemaPlus::Enums > <https://github.com/SchemaPlus/schema_plus_enums> gem is worth a look. > > I think the more interesting thing would to have > `ActiveRecord::Enum`backed by Postgres, but this raises hard questions > about cross-database compatibility. It's a bit of a can of worms! > > There's also an interesting post here > <http://www.railsonmaui.com/blog/2014/10/22/enums-and-queries-in-rails-4-dot-1/> > > that talks about some of the issues with the current implementation. I > believe some of these have been addressed by Rails 5. > > On Monday, May 23, 2016 at 8:25:42 AM UTC+10, Mike Dillon wrote: >> >> I'm interested in using Postgres's custom type support with Rails, >> particularly enumerated types >> <http://www.postgresql.org/docs/9.5/static/datatype-enum.html>. I see >> that this topic was previously brought up on this list here >> <https://groups.google.com/d/msg/rubyonrails-core/CrS3QPFkLos/Er7MfBIf3MYJ>, >> but it did not seem to generate any discussion. >> >> Would there be any interest in supporting Postgres custom enumerated >> types in ActiveRecord? >> >> As a first pass, I would want to ability to run "CREATE TYPE foo AS >> ENUM(...)" statements in migrations and have them captured in schema.rb, as >> well as being able to use custom types alongside native types in my column >> definitions. I could eventually see it making sense to allow ActiveRecord >> "enum" declarations to defer to a native database enumeration if it exists, >> but the "enum" method doesn't seem to have been aligned with the recent >> upgrades to the type system through the "attribute" keyword and >> ActiveRecord::Type. >> >> -md >> > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.