rails icon indicating copy to clipboard operation
rails copied to clipboard

Adding PG enum drop, rename, add value, rename value

Open rayfaddis opened this issue 2 years ago • 5 comments

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.

rayfaddis avatar Apr 14 '22 18:04 rayfaddis

2022-05-04 Update:

  1. Rebased
  2. Added irreversible migration error for inverting drop_enum without values
  3. Added add_enum_value to command recorder to get better irreversible migration error
  4. Added more tests around inversions without required attributes

rayfaddis avatar May 04 '22 14:05 rayfaddis

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 avatar Jun 14 '22 14:06 ghiculescu

@ghiculescu great idea, I have updated the guide as well, please see my second commit for that specifically.

rayfaddis avatar Aug 08 '22 00:08 rayfaddis

Support for dropping enums was merged to main in-between opening of this PR so this work no longer includes it.

rayfaddis avatar Aug 08 '22 01:08 rayfaddis

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.

ghiculescu avatar Aug 08 '22 14:08 ghiculescu

@yahonda @ghiculescu now that these updates have been made how is this looking to you two?

rayfaddis avatar Sep 29 '22 20:09 rayfaddis

Could you squash your commits?

ghiculescu avatar Oct 03 '22 20:10 ghiculescu

@ghiculescu I've squashed this down 👍

rayfaddis avatar Oct 05 '22 12:10 rayfaddis

Will be great to have this 👍🏻 .

vizcay avatar Feb 22 '23 21:02 vizcay

@sampatbadhe great suggestions to make the guide build better upon each example, this has been updated per your suggestions.

rayfaddis avatar Apr 04 '23 01:04 rayfaddis

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?

rayfaddis avatar Jun 02 '23 13:06 rayfaddis

Good call @yahonda, that has been updated!

rayfaddis avatar Jun 15 '23 14:06 rayfaddis