This commit is contained in:
Lance Pioch 2024-06-16 13:07:12 -04:00
parent c7bea4f024
commit ff261f9c99

View File

@ -1,5 +1,7 @@
<?php <?php
use App\Models\Objects\Endpoint;
use App\Models\Server;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -26,9 +28,19 @@ return new class extends Migration
} }
foreach ($portMappings as $serverId => $ports) { foreach ($portMappings as $serverId => $ports) {
DB::table('servers') /** @var Server $server */
->where('id', $serverId) $server = Server::find($serverId);
->update(['ports' => json_encode($ports)]); if (!$server) {
// Orphaned Allocations
continue;
}
foreach ($ports as $port) {
$server->ports ??= collect();
$server->ports->add(new Endpoint($port));
}
$server->save();
} }
try { try {
@ -36,7 +48,7 @@ return new class extends Migration
$table->dropForeign(['allocation_id']); $table->dropForeign(['allocation_id']);
}); });
} catch (Throwable) { } catch (Throwable) {
// pass for databases that don't support this like sqlite
} }
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
@ -56,28 +68,6 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table('nodes', function (Blueprint $table) { // Too much time to ensure this works correctly, please take a backup if necessary
$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();
});
} }
}; };