To extend on @rap-2-h's answer - here is a generic method you can use:
/**
* Alter an enum field constraints
* @param $table
* @param $field
* @param array $options
*/
protected function alterEnum($table, $field, array $options) {
$check = "${table}_${field}_check";
$enumList = [];
foreach($options as $option) {
$enumList[] = sprintf("'%s'::CHARACTER VARYING", $option);
}
$enumString = implode(", ", $enumList);
DB::transaction(function () use ($table, $field, $check, $options, $enumString) {
DB::statement(sprintf('ALTER TABLE %s DROP CONSTRAINT %s;', $table, $check));
DB::statement(sprintf('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s::TEXT = ANY (ARRAY[%s]::TEXT[]))', $table, $check, $field, $enumString));
});
}
Example usage:
$this->alterEnum('mytable', 'status', ['pending', 'accepted', 'canceled']);
Note that if you are dropping a constraint that is used in the table, you will need to either rename all instances to something that will be in the list, or delete all instances before you run this function