diff --git a/database/migrations/2023_01_03_185102_update_make_description_text_in_nests_table.php b/database/migrations/2023_01_03_185102_update_make_description_text_in_nests_table.php index e007ad5e..c907c635 100644 --- a/database/migrations/2023_01_03_185102_update_make_description_text_in_nests_table.php +++ b/database/migrations/2023_01_03_185102_update_make_description_text_in_nests_table.php @@ -2,6 +2,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,7 +15,7 @@ public function up() { Schema::table('nests', function (Blueprint $table) { - $table->text('description')->change(); + $table->text(column: 'description')->change(); }); } @@ -26,7 +27,13 @@ public function up() public function down() { Schema::table('nests', function (Blueprint $table) { - $table->string('description')->change(); + $oldvalues = DB::table('nests')->pluck('description'); + foreach ($oldvalues as $value) { + if (strlen($value) > 255) { + DB::table('nests')->update(['description' => substr($value, 0, 255)]); + } + } + $table->string(column: 'description', length: 255)->change(); }); } }; diff --git a/database/migrations/2023_01_12_135936_settings_to_text.php b/database/migrations/2023_01_12_135936_settings_to_text.php index 2b907b07..51b4fc63 100644 --- a/database/migrations/2023_01_12_135936_settings_to_text.php +++ b/database/migrations/2023_01_12_135936_settings_to_text.php @@ -2,6 +2,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration @@ -14,6 +15,7 @@ public function up() { Schema::table('settings', function (Blueprint $table) { + $table->text('value')->change(); }); } @@ -25,8 +27,14 @@ public function up() */ public function down() { - Schema::table('nests', function (Blueprint $table) { - $table->string('value')->change(); + Schema::table('settings', function (Blueprint $table) { + $oldvalues = DB::table('settings')->pluck('value'); + foreach ($oldvalues as $value) { + if (strlen($value) > 255) { + DB::table('settings')->update(['value' => substr($value, 0, 255)]); + } + } + $table->string('value', 255)->change(); }); } };