Fix migrations
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2024-07-14 20:19:17 +02:00
parent 757042bdd2
commit 885eaa5df5
1 changed files with 24 additions and 3 deletions

View File

@ -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']);
}
};