Skip to content

Instantly share code, notes, and snippets.

@coraxster
Created January 4, 2019 15:58
Show Gist options
  • Select an option

  • Save coraxster/41b7544e4481d4fe576b01c18ab51ab9 to your computer and use it in GitHub Desktop.

Select an option

Save coraxster/41b7544e4481d4fe576b01c18ab51ab9 to your computer and use it in GitHub Desktop.
Laravel pg bool workaround
<?php
class UpdateProblemColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('problem_table', function (Blueprint $table) {
$table->tinyInteger('problem_column_new')->default(0);
});
DB::table('problem_table')
->whereRaw('problem_column = true')
->update(['problem_column_new' => 1]);
Schema::table('problem_table', function (Blueprint $table) {
$table->dropColumn('problem_column');
$table->renameColumn('problem_column_new', 'problem_column');
});
}
public function down()
{
Schema::table('problem_table', function (Blueprint $table) {
$table->boolean('problem_column_new')->default(false);
});
DB::table('problem_table')
->whereRaw('problem_column = 1')
->update(['problem_column_new' => DB::raw('true')]);
Schema::table('problem_table', function (Blueprint $table) {
$table->dropColumn('problem_column');
$table->renameColumn('problem_column_new', 'problem_column');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment