Created
January 4, 2019 15:58
-
-
Save coraxster/41b7544e4481d4fe576b01c18ab51ab9 to your computer and use it in GitHub Desktop.
Laravel pg bool workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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