diff --git a/app/Models/Egg.php b/app/Models/Egg.php index a68d6b63d..3d621f8ac 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -139,6 +139,7 @@ class Egg extends Model 'features' => 'array', 'docker_images' => 'array', 'file_denylist' => 'array', + 'tags' => 'array', ]; } diff --git a/database/migrations/2024_03_12_154408_remove_nests_table.php b/database/migrations/2024_03_12_154408_remove_nests_table.php index b363de80d..e6f09546a 100644 --- a/database/migrations/2024_03_12_154408_remove_nests_table.php +++ b/database/migrations/2024_03_12_154408_remove_nests_table.php @@ -3,12 +3,30 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { public function up(): void { + Schema::table('eggs', function (Blueprint $table) { + $table->text('tags'); + }); + + DB::table('eggs')->update(['tags' => '[]']); + + $eggsWithNests = DB::table('eggs') + ->select(['eggs.id', 'nests.name']) + ->join('nests', 'nests.id', '=', 'eggs.nest_id') + ->get(); + + foreach ($eggsWithNests as $egg) { + DB::table('eggs') + ->where('id', $egg->id) + ->update(['tags' => "[\"$egg->name\"]"]); + } + Schema::table('eggs', function (Blueprint $table) { $table->dropForeign('service_options_nest_id_foreign'); $table->dropColumn('nest_id'); @@ -42,13 +60,14 @@ return new class extends Migration }); Schema::table('eggs', function (Blueprint $table) { + $table->dropColumn('tags'); $table->mediumInteger('nest_id')->unsigned(); - $table->foreign(['nest_id'], 'service_options_nest_id_foreign'); + // $table->foreign(['nest_id'], 'service_options_nest_id_foreign'); }); Schema::table('servers', function (Blueprint $table) { $table->mediumInteger('nest_id')->unsigned(); - $table->foreign(['nest_id'], 'servers_nest_id_foreign'); + // $table->foreign(['nest_id'], 'servers_nest_id_foreign'); }); if (class_exists('Database\Seeders\NestSeeder')) {