Better method describing how to change ENUM in `Active Record and PostgreSQL`

12 views
Skip to first unread message

Stefan Henzen

unread,
Jan 11, 2016, 5:30:10 AM1/11/16
to Ruby on Rails: Documentation
Hi there,

The method describing how to change an `ENUM` in `Active Record and PostgreSQL` is a bit awkward. It put me on the wrong path for a bit. I found you can also change an enum by:

* renaming it
* renaming all the columns using it
* creating a new enum
* creating a new column using that enum
* do some copying of values.

Advantages:
* It runs in a transaction
* You can add/remove/rename enum values

Here's a gist of the helper I created to do this in my project: https://gist.github.com/StefanH/fe5f27793ed2fccc4123. Used this on pretty big production tables, no problem. Should we change it?
Reply all
Reply to author
Forward
0 new messages