bibendi / activerecord-postgres_enum

Integrate PostgreSQL's enum data type into ActiveRecord's schema and migrations.
MIT License
361 stars 24 forks source link

add_enum_value with "if not exists" #23

Closed futuretap closed 4 years ago

futuretap commented 4 years ago

When I rollback and migrate again a migration that adds an enum value, I get an error:

ActiveRecord::StatementInvalid: PG::DuplicateObject: ERROR: enum label "unknown" already exists

This is my migration:

def up
  add_enum_value :review_image_category, 'unknown'
end

def down
  # there's no drop_enum_value
end

While Postgres indeed doesn't support ALTER TYPE DROP VALUE it does support ALTER TYPE ADD VALUE IF NOT EXISTS. Is this somehow accessible from the gem? An :if_not_exists parameter would be helpful.

bibendi commented 4 years ago

Hi! Makes sense! I'll try to implement this month.

hosembafer commented 4 years ago

@bibendi in case you didn't started yet, I will open the PR because currently I'm implementing the same stuff for my use.