loading...

re: Postgres enums with Rails VIEW POST

FULL DISCUSSION
 

Everything is great until we will need to add value to your enumeration

You can define your enums as a hash to make the mapping explicit, then AR will not remap your values when you add something.

 

Michael, thanks for your comment!
This is great idea, which comes after the fail without having explicit values first :)

 

Also if storage size is an issue then you can add the limit: option to the migration, which let's you select integer sizes:

gist.github.com/stream7/1069589/e0...

So in your example something like:

t.integer :status, null: false, limit: 1

On MySQL this will become a tinyint (1 byte) and on Postgres a smallint (2 bytes). Of course this doesn't solve the problem of enum values not being meaningful outside the app context.

code of conduct - report abuse