Skip to content

Instantly share code, notes, and snippets.

@iansltx
Created July 4, 2019 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iansltx/299d05d8776f1b096073bcb1fe1dcb36 to your computer and use it in GitHub Desktop.
Save iansltx/299d05d8776f1b096073bcb1fe1dcb36 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyExistingEnum extends Migration
{
public function up()
{
$values = implode(', ', array_map(function ($type) {
return "'" . $type . "'";
}, ['your', 'new', 'types', 'here']));
DB::statement('ALTER TABLE my_table DROP CONSTRAINT my_table_my_column_check,
ADD CONSTRAINT my_table_my_column_check CHECK (my_column::text = ANY (ARRAY['. $values . ']::text[]))');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment