rails
rails copied to clipboard
Adding PG enum drop, rename, add value, rename value
Summary
To expand on PostgreSQL enum support and the create_enum
command that comes with Rails 7, adding migration commands for rename_enum
, add_enum_value
, and rename_enum_value
.
Reversibility included with rename_enum
, and rename_enum_value
(all except add_enum_value
).
Other Information
Unable to add reversibility to add_enum_value
or a drop\remove_enum_value
command since PostgreSQL at this time does not support dropping enum type values.
Although enum types are primarily intended for static sets of values, there is support for adding new values to an existing enum type, and for renaming values (see ALTER TYPE). Existing values cannot be removed from an enum type, nor can the sort ordering of such values be changed, short of dropping and re-creating the enum type.
See https://www.postgresql.org/docs/current/datatype-enum.html.
2022-05-04 Update:
- Rebased
- Added irreversible migration error for inverting
drop_enum
without values - Added
add_enum_value
to command recorder to get better irreversible migration error - Added more tests around inversions without required attributes
This is awesome! Great to see more enum support being added.
Could you update the guides also? https://edgeguides.rubyonrails.org/active_record_postgresql.html#enumerated-types (sample PR: https://github.com/rails/rails/pull/44055)
@ghiculescu great idea, I have updated the guide as well, please see my second commit for that specifically.
Support for dropping enums was merged to main in-between opening of this PR so this work no longer includes it.
Support for dropping enums was merged to main in-between opening of this PR so this work no longer includes it.
Oh yeah sorry I totally forgot about this PR when doing https://github.com/rails/rails/pull/45735. Thanks for the update.
@yahonda @ghiculescu now that these updates have been made how is this looking to you two?
Could you squash your commits?
@ghiculescu I've squashed this down 👍
Will be great to have this 👍🏻 .
@sampatbadhe great suggestions to make the guide build better upon each example, this has been updated per your suggestions.
How are we feeling about this PR, it's been open for awhile (partly my fault), and I'd like to get it merged if we are happy with it.
Are we just waiting on @yahonda at this point?
Good call @yahonda, that has been updated!