New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add drop_enum
command for Postgres
#45735
Conversation
98a935b
to
fe2524e
Compare
% git grep -n 'DROP TYPE'
activerecord/test/cases/adapters/postgresql/composite_test.rb:35: @connection.execute "DROP TYPE IF EXISTS full_address"
activerecord/test/cases/adapters/postgresql/enum_test.rb:34: @connection.execute "DROP TYPE IF EXISTS mood"
activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb:405: @connection.execute "DROP TYPE IF EXISTS feeling"
activerecord/test/cases/adapters/postgresql/range_test.rb:101: @connection.execute "DROP TYPE IF EXISTS floatrange"
activerecord/test/cases/adapters/postgresql/range_test.rb:102: @connection.execute "DROP TYPE IF EXISTS stringrange"
guides/source/active_record_postgresql.md:270: DROP TYPE article_status;
%
|
@yahonda several of those (composite_test and range_test) are not enums, but other examples of custom types. Do you think I should add a more general I made the other changes as suggested - thanks for the schema reminder. |
Thanks for the update.
No, not necessary. I just git grep but did not verify each lines in detail. |
@@ -31,7 +31,7 @@ def setup | |||
|
|||
teardown do | |||
@connection.drop_table "postgresql_enums", if_exists: true | |||
@connection.execute "DROP TYPE IF EXISTS mood" | |||
@connection.drop_enum "mood" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding if_exists: true
support option for drop_enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah - good idea 👍
7caffde
to
85b3274
Compare
Thanks @yahonda |
Would you address the CHANGELOG.md conflicts? |
Yep 👍 |
Follow-up to rails#45735. Prior to this commit, `drop_enum` could not be reversed when called with the `if_exists: true` option, because `create_enum` could not accept options. This commit fixes that and adds test coverage. This commit also ensures that reversing `drop_enum` will raise an `ActiveRecord::IrreversibleMigration` error if no enum values are specified.
Follow up to #41469
This PR adds support for
drop_enum
, so you can drop enum types explicitly or through adb:migrate:down
.