From b24ff8bb2650a9ae7a49f729209e02fb972358f1 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sat, 15 Jun 2024 07:27:17 -0400 Subject: [PATCH] Unwrap transaction --- .../2024_06_06_043350_modify_allocations.php | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/database/migrations/2024_06_06_043350_modify_allocations.php b/database/migrations/2024_06_06_043350_modify_allocations.php index f8a4241d2..e6d2ce12d 100644 --- a/database/migrations/2024_06_06_043350_modify_allocations.php +++ b/database/migrations/2024_06_06_043350_modify_allocations.php @@ -12,42 +12,46 @@ return new class extends Migration */ public function up(): void { - DB::transaction(function () { - Schema::table('server_transfers', function (Blueprint $table) { - $table->dropColumn(['old_allocation', 'new_allocation', 'old_additional_allocations', 'new_additional_allocations']); - }); + Schema::table('server_transfers', function (Blueprint $table) { + $table->dropColumn(['old_allocation', 'new_allocation', 'old_additional_allocations', 'new_additional_allocations']); + }); - Schema::table('servers', function (Blueprint $table) { - $table->json('ports')->nullable(); - }); + Schema::table('servers', function (Blueprint $table) { + $table->json('ports')->nullable(); + }); - DB::table('servers')->update(['ports' => '[]']); + DB::table('servers')->update(['ports' => '[]']); - Schema::table('servers', function (Blueprint $table) { - $table->json('ports')->change(); - }); + Schema::table('servers', function (Blueprint $table) { + $table->json('ports')->change(); + }); - $portMappings = []; - foreach (DB::table('allocations')->get() as $allocation) { - $portMappings[$allocation->server_id][] = "$allocation->ip:$allocation->port"; + $portMappings = []; + foreach (DB::table('allocations')->get() as $allocation) { + $portMappings[$allocation->server_id][] = "$allocation->ip:$allocation->port"; + } + + foreach ($portMappings as $serverId => $ports) { + DB::table('servers') + ->where('id', $serverId) + ->update(['ports' => json_encode($ports)]); + } + + Schema::table('servers', function (Blueprint $table) { + try { + $table->dropForeign(['allocation_id']); + } catch (Exception) { + // pass } - foreach ($portMappings as $serverId => $ports) { - DB::table('servers') - ->where('id', $serverId) - ->update(['ports' => json_encode($ports)]); - } + $table->dropUnique(['allocation_id']); + $table->dropColumn(['allocation_id']); + }); - Schema::table('servers', function (Blueprint $table) { - $table->dropUnique(['allocation_id']); - $table->dropColumn(['allocation_id']); - }); + Schema::dropIfExists('allocations'); - Schema::dropIfExists('allocations'); - - Schema::table('nodes', function (Blueprint $table) { - $table->boolean('strict_ports')->default(true); - }); + Schema::table('nodes', function (Blueprint $table) { + $table->boolean('strict_ports')->default(true); }); }