Fix: graceful handling of missing modpack_installations table

- Cron and controller wrap modpack_installations queries in try/catch
- Falls through to egg variable / file detection if table missing
- Added migration with IF NOT EXISTS for fresh installs
- Migration won't drop the table (may be Pterodactyl-owned)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude (Chronicler #83 - The Compiler)
2026-04-13 00:44:28 -05:00
parent a256aa2090
commit 1783055c99
3 changed files with 53 additions and 13 deletions

View File

@@ -69,6 +69,8 @@ class CheckModpackUpdates extends Command
} }
// Step 1: modpack_installations table (fastest, most reliable) // Step 1: modpack_installations table (fastest, most reliable)
// This is a Pterodactyl table — may not exist on all panels
try {
$installation = DB::table('modpack_installations') $installation = DB::table('modpack_installations')
->where('server_id', $server->id) ->where('server_id', $server->id)
->first(); ->first();
@@ -77,6 +79,9 @@ class CheckModpackUpdates extends Command
$this->checkVersion($server, $installation->provider, (string) $installation->modpack_id, 'installer', null); $this->checkVersion($server, $installation->provider, (string) $installation->modpack_id, 'installer', null);
return; return;
} }
} catch (\Exception $e) {
// Table doesn't exist — skip this detection method
}
// Step 2: Egg variables // Step 2: Egg variables
$platform = $this->getVariable($server, 'MODPACK_PLATFORM'); $platform = $this->getVariable($server, 'MODPACK_PLATFORM');

View File

@@ -92,8 +92,9 @@ class ModpackAPIController extends Controller
}; };
} }
// 2. Check modpack_installations table // 2. Check modpack_installations table (Pterodactyl — may not exist)
if (empty($platform) || empty($modpackId)) { if (empty($platform) || empty($modpackId)) {
try {
$installation = DB::table('modpack_installations') $installation = DB::table('modpack_installations')
->where('server_id', $server->id) ->where('server_id', $server->id)
->first(); ->first();
@@ -101,6 +102,9 @@ class ModpackAPIController extends Controller
$platform = $platform ?: ($installation->provider ?? null); $platform = $platform ?: ($installation->provider ?? null);
$modpackId = $modpackId ?: (string) ($installation->modpack_id ?? ''); $modpackId = $modpackId ?: (string) ($installation->modpack_id ?? '');
} }
} catch (\Exception $e) {
// Table doesn't exist on this panel — skip
}
} }
// 3. If still nothing, try file detection // 3. If still nothing, try file detection

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Creates modpack_installations if it doesn't already exist.
* This table is normally created by Pterodactyl's modpack installer,
* but may be missing on panels without that feature.
* Safe to run on panels that already have it.
*/
return new class extends Migration
{
public function up(): void
{
if (!Schema::hasTable('modpack_installations')) {
Schema::create('modpack_installations', function (Blueprint $table) {
$table->unsignedBigInteger('server_id')->primary();
$table->string('provider', 191);
$table->string('modpack_id', 191);
$table->tinyInteger('finalized')->default(0);
});
}
}
public function down(): void
{
// Don't drop — this may be a Pterodactyl-owned table
}
};