diff --git a/database/migrations/2024_07_14_174642_create_formtemplates_mail_columns.php b/database/migrations/2024_07_14_174642_create_formtemplates_mail_columns.php index 8e84b26f..a50139b0 100644 --- a/database/migrations/2024_07_14_174642_create_formtemplates_mail_columns.php +++ b/database/migrations/2024_07_14_174642_create_formtemplates_mail_columns.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,10 +15,25 @@ return new class extends Migration public function up() { Schema::table('forms', function (Blueprint $table) { - $table->json('description')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change(); - $table->json('mail_top')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->nullable(false)->change(); - $table->json('mail_bottom')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->nullable(false)->change(); + $table->json('description')->default($this->default())->change(); + $table->json('mail_top')->default($this->default())->nullable(false)->change(); + $table->json('mail_bottom')->default($this->default())->nullable(false)->change(); }); + + foreach (DB::table('forms')->get() as $form) { + $mailTop = json_decode($form->mail_top, true); + if (!$mailTop || !count($mailTop)) { + DB::table('forms')->where('id', $form->id)->update(['mail_top' => $this->default()]); + } + $mailBottom = json_decode($form->mail_bottom, true); + if (!$mailBottom || !count($mailBottom)) { + DB::table('forms')->where('id', $form->id)->update(['mail_bottom' => $this->default()]); + } + $description = json_decode($form->description, true); + if (!$description || !count($description)) { + DB::table('forms')->where('id', $form->id)->update(['description' => $this->default()]); + } + } } /** @@ -33,4 +49,9 @@ return new class extends Migration $table->json('mail_bottom')->default(null)->nullable(true)->change(); }); } + + protected function default(): string + { + return json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']); + } };