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 e6f09546a..1805bb6f0 100644 --- a/database/migrations/2024_03_12_154408_remove_nests_table.php +++ b/database/migrations/2024_03_12_154408_remove_nests_table.php @@ -27,6 +27,7 @@ return new class extends Migration ->update(['tags' => "[\"$egg->name\"]"]); } + Schema::table('eggs', function (Blueprint $table) { $table->dropForeign('service_options_nest_id_foreign'); $table->dropColumn('nest_id'); @@ -44,6 +45,7 @@ return new class extends Migration }); } + // Not really reversible, but... public function down(): void { Schema::table('api_keys', function (Blueprint $table) { @@ -62,12 +64,12 @@ 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')) { diff --git a/database/migrations/2024_03_14_055537_remove_locations_table.php b/database/migrations/2024_03_14_055537_remove_locations_table.php index bf41cd464..7c72d7617 100644 --- a/database/migrations/2024_03_14_055537_remove_locations_table.php +++ b/database/migrations/2024_03_14_055537_remove_locations_table.php @@ -2,15 +2,30 @@ 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 { - /** - * Run the migrations. - */ public function up(): void { + Schema::table('nodes', function (Blueprint $table) { + $table->text('tags'); + }); + + DB::table('nodes')->update(['tags' => '[]']); + + $nodesWithLocations = DB::table('nodes') + ->select(['nodes.id', 'locations.short']) + ->join('locations', 'locations.id', '=', 'nodes.location_id') + ->get(); + + foreach ($nodesWithLocations as $node) { + DB::table('nodes') + ->where('id', $node->id) + ->update(['tags' => "[\"$node->short\"]"]); + } + Schema::table('nodes', function (Blueprint $table) { $table->dropForeign('nodes_location_id_foreign'); $table->dropColumn('location_id'); @@ -23,9 +38,7 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - */ + // Not really reversible, but... public function down(): void { Schema::create('locations', function (Blueprint $table) {