From ff261f9c99de57d8a57c6ab23c6d40b1f9061f9f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 16 Jun 2024 13:07:12 -0400 Subject: [PATCH] Realism --- .../2024_06_06_043350_modify_allocations.php | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/database/migrations/2024_06_06_043350_modify_allocations.php b/database/migrations/2024_06_06_043350_modify_allocations.php index ceeb51666..418b26ed9 100644 --- a/database/migrations/2024_06_06_043350_modify_allocations.php +++ b/database/migrations/2024_06_06_043350_modify_allocations.php @@ -1,5 +1,7 @@ $ports) { - DB::table('servers') - ->where('id', $serverId) - ->update(['ports' => json_encode($ports)]); + /** @var Server $server */ + $server = Server::find($serverId); + if (!$server) { + // Orphaned Allocations + + continue; + } + + foreach ($ports as $port) { + $server->ports ??= collect(); + $server->ports->add(new Endpoint($port)); + } + $server->save(); } try { @@ -36,7 +48,7 @@ return new class extends Migration $table->dropForeign(['allocation_id']); }); } catch (Throwable) { - + // pass for databases that don't support this like sqlite } Schema::table('servers', function (Blueprint $table) { @@ -56,28 +68,6 @@ return new class extends Migration */ public function down(): void { - Schema::table('nodes', function (Blueprint $table) { - $table->dropColumn('strict_ports'); - }); - - Schema::create('allocations', function (Blueprint $table) { - $table->id(); - $table->unsignedInteger('node_id'); - $table->string('ip'); - $table->text('ip_alias'); - $table->unsignedMediumInteger('port'); - $table->unsignedInteger('server_id'); - $table->string('notes')->default(''); - $table->timestamps(); - - $table->unique(['node_id', 'ip', 'port']); - }); - - Schema::table('server_transfers', function (Blueprint $table) { - $table->integer('old_node'); - $table->integer('new_node'); - $table->json('old_additional_allocations')->nullable(); - $table->json('new_additional_allocations')->nullable(); - }); + // Too much time to ensure this works correctly, please take a backup if necessary } };