You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run rails db:setup in my development environment and most the of the tables already exist, active record's create_table will drop the table for me by default because of the force: :cascade option in schema.rb. But when my schema.rb has instances of create_enum, they fail with the following error:
-- create_enum("boolean_operator_enum_type", ["any", "all"])
rails aborted!
ActiveRecord::StatementInvalid: PG::DuplicateObject: ERROR: type "boolean_operator_enum_type" already exists
: CREATE TYPE boolean_operator_enum_type AS ENUM ('any', 'all')
What are your thoughts on adding a force: :cascade option to create_enum, so that the enum can be dropped and db:setup can be run easier? I'd be more than happy to create the PR, but wanted to check your thoughts on it first: good idea? bad idea?
Note: As a current solution, I temporarily change my schema.rb to this:
module ActiveRecord
module PGEnum
module SchemaStatements
def drop_enum_if_exists_cascade(name, values_for_revert = nil)
execute("DROP TYPE IF EXISTS #{name} CASCADE").tap {
reload_type_map
}
end
end
end
end
ActiveRecord::Schema.define(version: 2020_12_22_214218) do
drop_enum_if_exists_cascade "boolean_operator_enum_type"
create_enum "boolean_operator_enum_type", ["any", "all"]
# ... rails schema here
end
The text was updated successfully, but these errors were encountered:
When I run
rails db:setup
in my development environment and most the of the tables already exist, active record'screate_table
will drop the table for me by default because of theforce: :cascade
option in schema.rb. But when my schema.rb has instances ofcreate_enum
, they fail with the following error:What are your thoughts on adding a
force: :cascade
option tocreate_enum
, so that theenum
can be dropped anddb:setup
can be run easier? I'd be more than happy to create the PR, but wanted to check your thoughts on it first: good idea? bad idea?Note: As a current solution, I temporarily change my
schema.rb
to this:The text was updated successfully, but these errors were encountered: