diff --git a/database/migrations/2020_04_03_230614_create_backups_table.php b/database/migrations/2020_04_03_230614_create_backups_table.php index ead68105c..10d0794d9 100644 --- a/database/migrations/2020_04_03_230614_create_backups_table.php +++ b/database/migrations/2020_04_03_230614_create_backups_table.php @@ -1,5 +1,6 @@ <?php +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; @@ -13,6 +14,21 @@ class CreateBackupsTable extends Migration */ public function up() { + $db = config('database.default'); + // There exists a backups plugin for the 0.7 version of the Panel. However, it didn't properly + // namespace itself so now we have to deal with these tables being in the way of tables we're trying + // to use. For now, just rename them to maintain the data. + $results = DB::select('SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = ? AND table_name LIKE ? AND table_name NOT LIKE \'%_plugin_bak\'', [ + config("database.connections.{$db}.database"), + 'backup%' + ]); + + // Take any of the results, most likely "backups" and "backup_logs" and rename them to have a + // suffix so data isn't completely lost, but they're no longer in the way of this migration... + foreach ($results as $result) { + Schema::rename($result['TABLE_NAME'], $result['TABLE_NAME'] . '_plugin_bak'); + } + Schema::create('backups', function (Blueprint $table) { $table->bigIncrements('id'); $table->unsignedInteger('server_id'); diff --git a/database/migrations/2020_04_26_111208_add_backup_limit_to_servers.php b/database/migrations/2020_04_26_111208_add_backup_limit_to_servers.php index 689da89b6..92121b7df 100644 --- a/database/migrations/2020_04_26_111208_add_backup_limit_to_servers.php +++ b/database/migrations/2020_04_26_111208_add_backup_limit_to_servers.php @@ -1,5 +1,6 @@ <?php +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; @@ -13,9 +14,23 @@ class AddBackupLimitToServers extends Migration */ public function up() { - Schema::table('servers', function (Blueprint $table) { - $table->unsignedInteger('backup_limit')->default(0)->after('database_limit'); - }); + $db = config('database.default'); + // Same as in the backups migration, we need to handle that plugin messing with the data structure + // here. If we find a result we'll actually keep the column around since we can maintain that backup + // limit, but we need to correct the column definition a bit. + $results = DB::select('SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = \'servers\' AND COLUMN_NAME = \'backup_limit\'', [ + config("database.connections.{$db}.database") + ]); + + if (count($results) === 1) { + Schema::table('servers', function (Blueprint $table) { + $table->unsignedInteger('backup_limit')->default(0)->change(); + }); + } else { + Schema::table('servers', function (Blueprint $table) { + $table->unsignedInteger('backup_limit')->default(0)->after('database_limit'); + }); + } } /**