On Thursday, July 9, 2020 at 8:54:42 AM UTC-7, Michael Monerau wrote:
>
> Hi,
>
> When using `add_enum_value` in an `up` block with pg_enum, what is the 
> best practice for the `down` block?
>
> I understand a `remove_enum_value` does not exist since it could leave 
> rows in a corrupt state.
>
> I'm inclined to leave the `down` block empty. But then, re-running the up 
> block and its `add_enum_value` would fail because the enum value already 
> exists (wasn't removed by the `down` block). That leaves the migrations in 
> a non-runnable state.
>
> So the migration is irreversible.
>
> Adding `add_enum_value?` similar to `create_table?` would provide a 
> good-enough workaround in my use case. Is it something that can be done 
> through pg_enum or with custom queries?
>

The best way to handle this is to raise an exception in the down block, to 
make it irreversible.  Then you shouldn't need to worry about the up block 
running when the enum value is already present. I'm not sure if that 
approach is considered acceptable.  If not, you'll have to change the up 
block to check for the existing enum values, and if the one you want to add 
is already present, then don't attempt to add it again.  I don't think it's 
worth adding an add_enum_value? method to handle that.

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/cf000b7a-082e-47b1-b633-2687620add91o%40googlegroups.com.

Reply via email to