Fix migrations to work with SQLite without needing SQLite CLI

This commit is contained in:
notCharles 2024-05-11 20:09:22 -04:00
parent 082163389a
commit e286100197
45 changed files with 350 additions and 218 deletions

View File

@ -3,7 +3,6 @@
namespace App\Filament\Resources\EggResource\Pages; namespace App\Filament\Resources\EggResource\Pages;
use App\Filament\Resources\EggResource; use App\Filament\Resources\EggResource;
use App\Models\User;
use Filament\Resources\Pages\CreateRecord; use Filament\Resources\Pages\CreateRecord;
use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor; use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
use Filament\Forms; use Filament\Forms;

View File

@ -1,6 +1,8 @@
<?php <?php
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration return new class extends Migration
{ {
@ -9,8 +11,9 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
$table = DB::getQueryGrammar()->wrapTable('tasks'); Schema::table('tasks', function (Blueprint $table) {
DB::statement('ALTER TABLE ' . $table . ' CHANGE `last_run` `last_run` TIMESTAMP NULL;'); $table->timestamp('last_run')->nullable()->change();
});
} }
/** /**
@ -18,7 +21,8 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
$table = DB::getQueryGrammar()->wrapTable('tasks'); Schema::table('tasks', function (Blueprint $table) {
DB::statement('ALTER TABLE ' . $table . ' CHANGE `last_run` `last_run` TIMESTAMP;'); $table->timestamp('last_run')->change();
});
} }
}; };

View File

@ -11,13 +11,14 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE servers
MODIFY COLUMN node INT(10) UNSIGNED NOT NULL, Schema::table('servers', function (Blueprint $table) {
MODIFY COLUMN owner INT(10) UNSIGNED NOT NULL, $table->unsignedInteger('node')->change();
MODIFY COLUMN allocation INT(10) UNSIGNED NOT NULL, $table->unsignedInteger('owner')->change();
MODIFY COLUMN service INT(10) UNSIGNED NOT NULL, $table->unsignedInteger('allocation')->change();
MODIFY COLUMN `option` INT(10) UNSIGNED NOT NULL $table->unsignedInteger('service')->change();
'); $table->unsignedInteger('option')->change();
});
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->foreign('node')->references('id')->on('nodes'); $table->foreign('node')->references('id')->on('nodes');
@ -50,12 +51,12 @@ return new class extends Migration
$table->dropColumn('deleted_at'); $table->dropColumn('deleted_at');
}); });
DB::statement('ALTER TABLE servers Schema::table('servers', function (Blueprint $table) {
MODIFY COLUMN node MEDIUMINT(8) UNSIGNED NOT NULL, $table->unsignedMediumInteger('node')->change();
MODIFY COLUMN owner MEDIUMINT(8) UNSIGNED NOT NULL, $table->unsignedMediumInteger('owner')->change();
MODIFY COLUMN allocation MEDIUMINT(8) UNSIGNED NOT NULL, $table->unsignedMediumInteger('allocation')->change();
MODIFY COLUMN service MEDIUMINT(8) UNSIGNED NOT NULL, $table->unsignedMediumInteger('service')->change();
MODIFY COLUMN `option` MEDIUMINT(8) UNSIGNED NOT NULL $table->unsignedMediumInteger('option')->change();
'); });
} }
}; };

View File

@ -11,10 +11,10 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE allocations Schema::table('allocations', function (Blueprint $table) {
MODIFY COLUMN assigned_to INT(10) UNSIGNED NULL, $table->unsignedInteger('assigned_to')->change();
MODIFY COLUMN node INT(10) UNSIGNED NOT NULL $table->unsignedInteger('node')->change();
'); });
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->foreign('assigned_to')->references('id')->on('servers'); $table->foreign('assigned_to')->references('id')->on('servers');
@ -35,9 +35,9 @@ return new class extends Migration
$table->dropIndex('allocations_node_foreign'); $table->dropIndex('allocations_node_foreign');
}); });
DB::statement('ALTER TABLE allocations Schema::table('allocations', function (Blueprint $table) {
MODIFY COLUMN assigned_to MEDIUMINT(8) UNSIGNED NULL, $table->unsignedMediumInteger('assigned_to')->change();
MODIFY COLUMN node MEDIUMINT(8) UNSIGNED NOT NULL $table->unsignedMediumInteger('node')->change();
'); });
} }
}; };

View File

@ -11,7 +11,9 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE api_permissions MODIFY key_id INT(10) UNSIGNED NOT NULL'); Schema::table('api_permissions', function (Blueprint $table) {
$table->unsignedInteger('key_id')->change();
});
Schema::table('api_permissions', function (Blueprint $table) { Schema::table('api_permissions', function (Blueprint $table) {
$table->foreign('key_id')->references('id')->on('api_keys'); $table->foreign('key_id')->references('id')->on('api_keys');
@ -28,6 +30,8 @@ return new class extends Migration
$table->dropIndex('api_permissions_key_id_foreign'); $table->dropIndex('api_permissions_key_id_foreign');
}); });
DB::statement('ALTER TABLE api_permissions MODIFY key_id MEDIUMINT(8) UNSIGNED NOT NULL'); Schema::table('api_permissions', function (Blueprint $table) {
$table->unsignedMediumInteger('key_id')->change();
});
} }
}; };

View File

@ -11,7 +11,9 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE nodes MODIFY location INT(10) UNSIGNED NOT NULL'); Schema::table('nodes', function (Blueprint $table) {
$table->unsignedInteger('location')->change();
});
Schema::table('nodes', function (Blueprint $table) { Schema::table('nodes', function (Blueprint $table) {
$table->foreign('location')->references('id')->on('locations'); $table->foreign('location')->references('id')->on('locations');
@ -28,6 +30,8 @@ return new class extends Migration
$table->dropIndex('nodes_location_foreign'); $table->dropIndex('nodes_location_foreign');
}); });
DB::statement('ALTER TABLE nodes MODIFY location MEDIUMINT(10) UNSIGNED NOT NULL'); Schema::table('nodes', function (Blueprint $table) {
$table->unsignedMediumInteger('location')->change();
});
} }
}; };

View File

@ -11,10 +11,10 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE server_variables Schema::table('server_variables', function (Blueprint $table) {
MODIFY COLUMN server_id INT(10) UNSIGNED NULL, $table->unsignedInteger('server_id')->change();
MODIFY COLUMN variable_id INT(10) UNSIGNED NOT NULL $table->unsignedInteger('variable_id')->change();
'); });
Schema::table('server_variables', function (Blueprint $table) { Schema::table('server_variables', function (Blueprint $table) {
$table->foreign('server_id')->references('id')->on('servers'); $table->foreign('server_id')->references('id')->on('servers');
@ -32,9 +32,10 @@ return new class extends Migration
$table->dropForeign(['variable_id']); $table->dropForeign(['variable_id']);
}); });
DB::statement('ALTER TABLE server_variables Schema::table('server_variables', function (Blueprint $table) {
MODIFY COLUMN server_id MEDIUMINT(8) UNSIGNED NULL, $table->unsignedMediumInteger('server_id')->change();
MODIFY COLUMN variable_id MEDIUMINT(8) UNSIGNED NOT NULL $table->unsignedMediumInteger('variable_id')->change();
'); });
} }
}; };

View File

@ -11,7 +11,9 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE service_options MODIFY parent_service INT(10) UNSIGNED NOT NULL'); Schema::table('service_options', function (Blueprint $table) {
$table->unsignedInteger('parent_service')->change();
});
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->foreign('parent_service')->references('id')->on('services'); $table->foreign('parent_service')->references('id')->on('services');
@ -28,6 +30,8 @@ return new class extends Migration
$table->dropIndex('service_options_parent_service_foreign'); $table->dropIndex('service_options_parent_service_foreign');
}); });
DB::statement('ALTER TABLE service_options MODIFY parent_service MEDIUMINT(8) UNSIGNED NOT NULL'); Schema::table('service_options', function (Blueprint $table) {
$table->unsignedMediumInteger('parent_service')->change();
});
} }
}; };

View File

@ -11,7 +11,9 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE service_variables MODIFY option_id INT(10) UNSIGNED NOT NULL'); Schema::table('service_variables', function (Blueprint $table) {
$table->unsignedInteger('option_id')->change();
});
Schema::table('service_variables', function (Blueprint $table) { Schema::table('service_variables', function (Blueprint $table) {
$table->foreign('option_id')->references('id')->on('service_options'); $table->foreign('option_id')->references('id')->on('service_options');
@ -28,6 +30,8 @@ return new class extends Migration
$table->dropIndex('service_variables_option_id_foreign'); $table->dropIndex('service_variables_option_id_foreign');
}); });
DB::statement('ALTER TABLE service_variables MODIFY option_id MEDIUMINT(8) UNSIGNED NOT NULL'); Schema::table('service_variables', function (Blueprint $table) {
$table->unsignedMediumInteger('option_id')->change();
});
} }
}; };

View File

@ -12,19 +12,21 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign('servers_node_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('servers_owner_foreign'); $table->dropForeign('servers_node_foreign');
$table->dropForeign('servers_allocation_foreign'); $table->dropForeign('servers_owner_foreign');
$table->dropForeign('servers_service_foreign'); $table->dropForeign('servers_allocation_foreign');
$table->dropForeign('servers_option_foreign'); $table->dropForeign('servers_service_foreign');
$table->dropForeign('servers_pack_foreign'); $table->dropForeign('servers_option_foreign');
$table->dropForeign('servers_pack_foreign');
$table->dropIndex('servers_node_foreign'); $table->dropIndex('servers_node_foreign');
$table->dropIndex('servers_owner_foreign'); $table->dropIndex('servers_owner_foreign');
$table->dropIndex('servers_allocation_foreign'); $table->dropIndex('servers_allocation_foreign');
$table->dropIndex('servers_service_foreign'); $table->dropIndex('servers_service_foreign');
$table->dropIndex('servers_option_foreign'); $table->dropIndex('servers_option_foreign');
$table->dropIndex('servers_pack_foreign'); $table->dropIndex('servers_pack_foreign');
}
$table->renameColumn('node', 'node_id'); $table->renameColumn('node', 'node_id');
$table->renameColumn('owner', 'owner_id'); $table->renameColumn('owner', 'owner_id');
@ -50,11 +52,13 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['owner_id']); $table->dropForeign(['node_id']);
$table->dropForeign(['allocation_id']); $table->dropForeign(['owner_id']);
$table->dropForeign(['service_id']); $table->dropForeign(['allocation_id']);
$table->dropForeign(['option_id']); $table->dropForeign(['service_id']);
$table->dropForeign(['option_id']);
}
$table->renameColumn('node_id', 'node'); $table->renameColumn('node_id', 'node');
$table->renameColumn('owner_id', 'owner'); $table->renameColumn('owner_id', 'owner');

View File

@ -12,8 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('nodes', function (Blueprint $table) { Schema::table('nodes', function (Blueprint $table) {
$table->dropForeign('nodes_location_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('nodes_location_foreign'); $table->dropForeign('nodes_location_foreign');
$table->dropIndex('nodes_location_foreign');
}
$table->renameColumn('location', 'location_id'); $table->renameColumn('location', 'location_id');
$table->foreign('location_id')->references('id')->on('locations'); $table->foreign('location_id')->references('id')->on('locations');
@ -26,8 +28,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('nodes', function (Blueprint $table) { Schema::table('nodes', function (Blueprint $table) {
$table->dropForeign('nodes_location_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('nodes_location_id_foreign'); $table->dropForeign('nodes_location_id_foreign');
$table->dropIndex('nodes_location_id_foreign');
}
$table->renameColumn('location_id', 'location'); $table->renameColumn('location_id', 'location');
$table->foreign('location')->references('id')->on('locations'); $table->foreign('location')->references('id')->on('locations');

View File

@ -12,10 +12,12 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign('allocations_node_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('allocations_assigned_to_foreign'); $table->dropForeign('allocations_node_foreign');
$table->dropIndex('allocations_node_foreign'); $table->dropForeign('allocations_assigned_to_foreign');
$table->dropIndex('allocations_assigned_to_foreign'); $table->dropIndex('allocations_node_foreign');
$table->dropIndex('allocations_assigned_to_foreign');
}
$table->renameColumn('node', 'node_id'); $table->renameColumn('node', 'node_id');
$table->renameColumn('assigned_to', 'server_id'); $table->renameColumn('assigned_to', 'server_id');
@ -30,10 +32,12 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign('allocations_node_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('allocations_server_id_foreign'); $table->dropForeign('allocations_node_id_foreign');
$table->dropIndex('allocations_node_id_foreign'); $table->dropForeign('allocations_server_id_foreign');
$table->dropIndex('allocations_server_id_foreign'); $table->dropIndex('allocations_node_id_foreign');
$table->dropIndex('allocations_server_id_foreign');
}
$table->renameColumn('node_id', 'node'); $table->renameColumn('node_id', 'node');
$table->renameColumn('server_id', 'assigned_to'); $table->renameColumn('server_id', 'assigned_to');

View File

@ -12,8 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign('service_options_parent_service_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('service_options_parent_service_foreign'); $table->dropForeign('service_options_parent_service_foreign');
$table->dropIndex('service_options_parent_service_foreign');
}
$table->renameColumn('parent_service', 'service_id'); $table->renameColumn('parent_service', 'service_id');
$table->foreign('service_id')->references('id')->on('services'); $table->foreign('service_id')->references('id')->on('services');
@ -26,8 +28,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign('service_options_service_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('service_options_service_id_foreign'); $table->dropForeign('service_options_service_id_foreign');
$table->dropIndex('service_options_service_id_foreign');
}
$table->renameColumn('service_id', 'parent_service'); $table->renameColumn('service_id', 'parent_service');
$table->foreign('parent_service')->references('id')->on('services'); $table->foreign('parent_service')->references('id')->on('services');

View File

@ -12,8 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('service_packs', function (Blueprint $table) { Schema::table('service_packs', function (Blueprint $table) {
$table->dropForeign('service_packs_option_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('service_packs_option_foreign'); $table->dropForeign('service_packs_option_foreign');
$table->dropIndex('service_packs_option_foreign');
}
$table->renameColumn('option', 'option_id'); $table->renameColumn('option', 'option_id');
$table->foreign('option_id')->references('id')->on('service_options'); $table->foreign('option_id')->references('id')->on('service_options');
@ -26,8 +28,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('service_packs', function (Blueprint $table) { Schema::table('service_packs', function (Blueprint $table) {
$table->dropForeign('service_packs_option_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('service_packs_option_id_foreign'); $table->dropForeign('service_packs_option_id_foreign');
$table->dropIndex('service_packs_option_id_foreign');
}
$table->renameColumn('option_id', 'option'); $table->renameColumn('option_id', 'option');
$table->foreign('option')->references('id')->on('service_options'); $table->foreign('option')->references('id')->on('service_options');

View File

@ -26,10 +26,12 @@ return new class extends Migration
}); });
Schema::table('permissions', function (Blueprint $table) { Schema::table('permissions', function (Blueprint $table) {
$table->dropForeign('permissions_server_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('permissions_server_id_foreign'); $table->dropForeign('permissions_server_id_foreign');
$table->dropForeign('permissions_user_id_foreign'); $table->dropIndex('permissions_server_id_foreign');
$table->dropIndex('permissions_user_id_foreign'); $table->dropForeign('permissions_user_id_foreign');
$table->dropIndex('permissions_user_id_foreign');
}
$table->dropColumn('server_id'); $table->dropColumn('server_id');
$table->dropColumn('user_id'); $table->dropColumn('user_id');
@ -60,8 +62,10 @@ return new class extends Migration
}); });
Schema::table('permissions', function (Blueprint $table) { Schema::table('permissions', function (Blueprint $table) {
$table->dropForeign('permissions_subuser_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropIndex('permissions_subuser_id_foreign'); $table->dropForeign('permissions_subuser_id_foreign');
$table->dropIndex('permissions_subuser_id_foreign');
}
$table->dropColumn('subuser_id'); $table->dropColumn('subuser_id');
$table->foreign('server_id')->references('id')->on('servers'); $table->foreign('server_id')->references('id')->on('servers');

View File

@ -12,7 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('api_keys', function (Blueprint $table) { Schema::table('api_keys', function (Blueprint $table) {
$table->dropForeign('api_keys_user_foreign')->dropIndex('api_keys_user_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('api_keys_user_foreign');
$table->dropIndex('api_keys_user_foreign');
}
$table->renameColumn('user', 'user_id'); $table->renameColumn('user', 'user_id');
$table->foreign('user_id')->references('id')->on('users'); $table->foreign('user_id')->references('id')->on('users');
@ -25,7 +28,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('api_keys', function (Blueprint $table) { Schema::table('api_keys', function (Blueprint $table) {
$table->dropForeign('api_keys_user_id_foreign')->dropIndex('api_keys_user_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('api_keys_user_id_foreign');
$table->dropIndex('api_keys_user_id_foreign');
}
$table->renameColumn('user_id', 'user'); $table->renameColumn('user_id', 'user');
$table->foreign('user')->references('id')->on('users'); $table->foreign('user')->references('id')->on('users');

View File

@ -12,7 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('node_configuration_tokens', function (Blueprint $table) { Schema::table('node_configuration_tokens', function (Blueprint $table) {
$table->dropForeign(['node']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node']);
}
$table->dropColumn('expires_at'); $table->dropColumn('expires_at');
$table->renameColumn('node', 'node_id'); $table->renameColumn('node', 'node_id');
@ -26,7 +29,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('node_configuration_tokens', function (Blueprint $table) { Schema::table('node_configuration_tokens', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
}
$table->renameColumn('node_id', 'node'); $table->renameColumn('node_id', 'node');
$table->timestamp('expires_at')->after('token'); $table->timestamp('expires_at')->after('token');

View File

@ -11,9 +11,11 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table('service_packs', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']); Schema::table('service_packs', function (Blueprint $table) {
}); $table->dropForeign(['option_id']);
});
}
Schema::rename('service_packs', 'packs'); Schema::rename('service_packs', 'packs');
@ -27,9 +29,11 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table('packs', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']); Schema::table('packs', function (Blueprint $table) {
}); $table->dropForeign(['option_id']);
});
}
Schema::rename('packs', 'service_packs'); Schema::rename('packs', 'service_packs');

View File

@ -11,9 +11,11 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
Schema::table('database_servers', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['linked_node']); Schema::table('database_servers', function (Blueprint $table) {
}); $table->dropForeign(['linked_node']);
});
}
Schema::rename('database_servers', 'database_hosts'); Schema::rename('database_servers', 'database_hosts');
@ -29,9 +31,11 @@ return new class extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table('database_hosts', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']); Schema::table('database_hosts', function (Blueprint $table) {
}); $table->dropForeign(['node_id']);
});
}
Schema::rename('database_hosts', 'database_servers'); Schema::rename('database_hosts', 'database_servers');

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('databases', function (Blueprint $table) { Schema::table('databases', function (Blueprint $table) {
$table->dropForeign(['db_server']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['db_server']);
}
$table->renameColumn('db_server', 'database_host_id'); $table->renameColumn('db_server', 'database_host_id');
@ -26,7 +28,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('databases', function (Blueprint $table) { Schema::table('databases', function (Blueprint $table) {
$table->dropForeign(['database_host_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['database_host_id']);
}
$table->renameColumn('database_host_id', 'db_server'); $table->renameColumn('database_host_id', 'db_server');

View File

@ -13,7 +13,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('tasks', function (Blueprint $table) { Schema::table('tasks', function (Blueprint $table) {
$table->dropForeign(['server']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['server']);
}
$table->renameColumn('server', 'server_id'); $table->renameColumn('server', 'server_id');
$table->unsignedInteger('user_id')->nullable()->after('id'); $table->unsignedInteger('user_id')->nullable()->after('id');
@ -36,8 +38,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('tasks', function (Blueprint $table) { Schema::table('tasks', function (Blueprint $table) {
// $table->dropForeign(['server_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
// $table->dropForeign(['user_id']); $table->dropForeign(['server_id']);
$table->dropForeign(['user_id']);
}
$table->renameColumn('server_id', 'server'); $table->renameColumn('server_id', 'server');
$table->dropColumn('user_id'); $table->dropColumn('user_id');

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('api_permissions', function (Blueprint $table) { Schema::table('api_permissions', function (Blueprint $table) {
$table->dropForeign(['key_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['key_id']);
}
$table->foreign('key_id')->references('id')->on('api_keys')->onDelete('cascade'); $table->foreign('key_id')->references('id')->on('api_keys')->onDelete('cascade');
}); });
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('api_permissions', function (Blueprint $table) { Schema::table('api_permissions', function (Blueprint $table) {
$table->dropForeign(['key_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['key_id']);
}
$table->foreign('key_id')->references('id')->on('api_keys'); $table->foreign('key_id')->references('id')->on('api_keys');
}); });

View File

@ -12,14 +12,18 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('permissions', function (Blueprint $table) { Schema::table('permissions', function (Blueprint $table) {
$table->dropForeign(['subuser_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['subuser_id']);
}
$table->foreign('subuser_id')->references('id')->on('subusers')->onDelete('cascade'); $table->foreign('subuser_id')->references('id')->on('subusers')->onDelete('cascade');
}); });
Schema::table('subusers', function (Blueprint $table) { Schema::table('subusers', function (Blueprint $table) {
$table->dropForeign(['user_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['server_id']); $table->dropForeign(['user_id']);
$table->dropForeign(['server_id']);
}
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade'); $table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade');
@ -32,15 +36,19 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('subusers', function (Blueprint $table) { Schema::table('subusers', function (Blueprint $table) {
$table->dropForeign(['user_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['server_id']); $table->dropForeign(['user_id']);
$table->dropForeign(['server_id']);
}
$table->foreign('user_id')->references('id')->on('users'); $table->foreign('user_id')->references('id')->on('users');
$table->foreign('server_id')->references('id')->on('servers'); $table->foreign('server_id')->references('id')->on('servers');
}); });
Schema::table('permissions', function (Blueprint $table) { Schema::table('permissions', function (Blueprint $table) {
$table->dropForeign(['subuser_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['subuser_id']);
}
$table->foreign('subuser_id')->references('id')->on('subusers'); $table->foreign('subuser_id')->references('id')->on('subusers');
}); });

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign(['server_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['server_id']);
}
$table->foreign('server_id')->references('id')->on('servers')->onDelete('set null'); $table->foreign('server_id')->references('id')->on('servers')->onDelete('set null');
}); });
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign(['server_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['server_id']);
}
$table->foreign('server_id')->references('id')->on('servers'); $table->foreign('server_id')->references('id')->on('servers');
}); });

View File

@ -12,8 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('server_variables', function (Blueprint $table) { Schema::table('server_variables', function (Blueprint $table) {
$table->dropForeign(['server_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['variable_id']); $table->dropForeign(['server_id']);
$table->dropForeign(['variable_id']);
}
$table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade'); $table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade');
$table->foreign('variable_id')->references('id')->on('service_variables')->onDelete('cascade'); $table->foreign('variable_id')->references('id')->on('service_variables')->onDelete('cascade');
@ -26,8 +28,10 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('server_variables', function (Blueprint $table) { Schema::table('server_variables', function (Blueprint $table) {
$table->dropForeign(['server_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['variable_id']); $table->dropForeign(['server_id']);
$table->dropForeign(['variable_id']);
}
$table->foreign('server_id')->references('id')->on('servers'); $table->foreign('server_id')->references('id')->on('servers');
$table->foreign('variable_id')->references('id')->on('service_variables'); $table->foreign('variable_id')->references('id')->on('service_variables');

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('tasks', function (Blueprint $table) { Schema::table('tasks', function (Blueprint $table) {
$table->dropForeign(['server_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['server_id']);
}
$table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade'); $table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade');
}); });

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('database_hosts', function (Blueprint $table) { Schema::table('database_hosts', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
}
$table->foreign('node_id')->references('id')->on('nodes')->onDelete('set null'); $table->foreign('node_id')->references('id')->on('nodes')->onDelete('set null');
}); });
} }
@ -23,7 +25,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('database_hosts', function (Blueprint $table) { Schema::table('database_hosts', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
}
$table->foreign('node_id')->references('id')->on('nodes'); $table->foreign('node_id')->references('id')->on('nodes');
}); });
} }

View File

@ -23,8 +23,8 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('nodes', function (Blueprint $table) { Schema::table('nodes', function (Blueprint $table) {
DB::statement('ALTER TABLE nodes MODIFY disk_overallocate MEDIUMINT UNSIGNED NULL, $table->unsignedMediumInteger('disk_overallocate')->nullable();
MODIFY memory_overallocate MEDIUMINT UNSIGNED NULL'); $table->unsignedMediumInteger('memory_overallocate')->nullable();
}); });
} }
}; };

View File

@ -22,7 +22,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
}
$table->dropUnique(['node_id', 'ip', 'port']); $table->dropUnique(['node_id', 'ip', 'port']);
$table->foreign('node_id')->references('id')->on('nodes'); $table->foreign('node_id')->references('id')->on('nodes');
}); });

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign(['service_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['service_id']);
}
$table->foreign('service_id')->references('id')->on('services')->onDelete('cascade'); $table->foreign('service_id')->references('id')->on('services')->onDelete('cascade');
}); });
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign(['service_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['service_id']);
}
$table->foreign('service_id')->references('id')->on('services'); $table->foreign('service_id')->references('id')->on('services');
}); });

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('packs', function (Blueprint $table) { Schema::table('packs', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']);
}
$table->foreign('option_id')->references('id')->on('service_options')->onDelete('cascade'); $table->foreign('option_id')->references('id')->on('service_options')->onDelete('cascade');
}); });
@ -24,8 +26,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('packs', function (Blueprint $table) { Schema::table('packs', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']);
}
$table->foreign('option_id')->references('id')->on('service_options'); $table->foreign('option_id')->references('id')->on('service_options');
}); });
} }

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('service_variables', function (Blueprint $table) { Schema::table('service_variables', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']);
}
$table->foreign('option_id')->references('id')->on('service_options')->onDelete('CASCADE'); $table->foreign('option_id')->references('id')->on('service_options')->onDelete('CASCADE');
}); });
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('service_variables', function (Blueprint $table) { Schema::table('service_variables', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']);
}
$table->foreign('option_id')->references('id')->on('service_options'); $table->foreign('option_id')->references('id')->on('service_options');
}); });

View File

@ -1,5 +1,6 @@
<?php <?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
@ -15,14 +16,18 @@ return new class extends Migration
Schema::rename('services', 'nests'); Schema::rename('services', 'nests');
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['service_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['service_id']);
}
$table->renameColumn('service_id', 'nest_id'); $table->renameColumn('service_id', 'nest_id');
$table->foreign('nest_id')->references('id')->on('nests'); $table->foreign('nest_id')->references('id')->on('nests');
}); });
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign(['service_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['service_id']);
}
$table->renameColumn('service_id', 'nest_id'); $table->renameColumn('service_id', 'nest_id');
$table->foreign('nest_id')->references('id')->on('nests')->onDelete('CASCADE'); $table->foreign('nest_id')->references('id')->on('nests')->onDelete('CASCADE');
@ -41,14 +46,18 @@ return new class extends Migration
Schema::rename('nests', 'services'); Schema::rename('nests', 'services');
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['nest_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['nest_id']);
}
$table->renameColumn('nest_id', 'service_id'); $table->renameColumn('nest_id', 'service_id');
$table->foreign('service_id')->references('id')->on('services'); $table->foreign('service_id')->references('id')->on('services');
}); });
Schema::table('service_options', function (Blueprint $table) { Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign(['nest_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['nest_id']);
}
$table->renameColumn('nest_id', 'service_id'); $table->renameColumn('nest_id', 'service_id');
$table->foreign('service_id')->references('id')->on('services')->onDelete('CASCADE'); $table->foreign('service_id')->references('id')->on('services')->onDelete('CASCADE');

View File

@ -1,5 +1,6 @@
<?php <?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
@ -12,24 +13,30 @@ return new class extends Migration
{ {
Schema::disableForeignKeyConstraints(); Schema::disableForeignKeyConstraints();
Schema::table('service_options', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['config_from']); Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign(['copy_script_from']); $table->dropForeign(['config_from']);
}); $table->dropForeign(['copy_script_from']);
});
}
Schema::rename('service_options', 'eggs'); Schema::rename('service_options', 'eggs');
Schema::table('packs', function (Blueprint $table) { Schema::table('packs', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->renameColumn('option_id', 'egg_id'); $table->dropForeign(['option_id']);
}
$table->renameColumn('option_id', 'egg_id');
$table->foreign('egg_id')->references('id')->on('eggs')->onDelete('CASCADE'); $table->foreign('egg_id')->references('id')->on('eggs')->onDelete('CASCADE');
}); });
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->renameColumn('option_id', 'egg_id'); $table->dropForeign(['option_id']);
}
$table->renameColumn('option_id', 'egg_id');
$table->foreign('egg_id')->references('id')->on('eggs'); $table->foreign('egg_id')->references('id')->on('eggs');
}); });
@ -39,7 +46,10 @@ return new class extends Migration
}); });
Schema::table('service_variables', function (Blueprint $table) { Schema::table('service_variables', function (Blueprint $table) {
$table->dropForeign(['option_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['option_id']);
}
$table->renameColumn('option_id', 'egg_id'); $table->renameColumn('option_id', 'egg_id');
$table->foreign('egg_id')->references('id')->on('eggs')->onDelete('CASCADE'); $table->foreign('egg_id')->references('id')->on('eggs')->onDelete('CASCADE');
@ -55,24 +65,30 @@ return new class extends Migration
{ {
Schema::disableForeignKeyConstraints(); Schema::disableForeignKeyConstraints();
Schema::table('eggs', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['config_from']); Schema::table('eggs', function (Blueprint $table) {
$table->dropForeign(['copy_script_from']); $table->dropForeign(['config_from']);
}); $table->dropForeign(['copy_script_from']);
});
}
Schema::rename('eggs', 'service_options'); Schema::rename('eggs', 'service_options');
Schema::table('packs', function (Blueprint $table) { Schema::table('packs', function (Blueprint $table) {
$table->dropForeign(['egg_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->renameColumn('egg_id', 'option_id'); $table->dropForeign(['egg_id']);
}
$table->renameColumn('egg_id', 'option_id');
$table->foreign('option_id')->references('id')->on('service_options')->onDelete('CASCADE'); $table->foreign('option_id')->references('id')->on('service_options')->onDelete('CASCADE');
}); });
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['egg_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->renameColumn('egg_id', 'option_id'); $table->dropForeign(['egg_id']);
}
$table->renameColumn('egg_id', 'option_id');
$table->foreign('option_id')->references('id')->on('service_options'); $table->foreign('option_id')->references('id')->on('service_options');
}); });
@ -82,9 +98,11 @@ return new class extends Migration
}); });
Schema::table('service_variables', function (Blueprint $table) { Schema::table('service_variables', function (Blueprint $table) {
$table->dropForeign(['egg_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->renameColumn('egg_id', 'option_id'); $table->dropForeign(['egg_id']);
}
$table->renameColumn('egg_id', 'option_id');
$table->foreign('option_id')->references('id')->on('options')->onDelete('CASCADE'); $table->foreign('option_id')->references('id')->on('options')->onDelete('CASCADE');
}); });

View File

@ -1,5 +1,6 @@
<?php <?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
@ -15,7 +16,9 @@ return new class extends Migration
Schema::rename('service_variables', 'egg_variables'); Schema::rename('service_variables', 'egg_variables');
Schema::table('server_variables', function (Blueprint $table) { Schema::table('server_variables', function (Blueprint $table) {
$table->dropForeign(['variable_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['variable_id']);
}
$table->foreign('variable_id')->references('id')->on('egg_variables')->onDelete('CASCADE'); $table->foreign('variable_id')->references('id')->on('egg_variables')->onDelete('CASCADE');
}); });
@ -33,7 +36,9 @@ return new class extends Migration
Schema::rename('egg_variables', 'service_variables'); Schema::rename('egg_variables', 'service_variables');
Schema::table('server_variables', function (Blueprint $table) { Schema::table('server_variables', function (Blueprint $table) {
$table->dropForeign(['variable_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['variable_id']);
}
$table->foreign('variable_id')->references('id')->on('service_variables')->onDelete('CASCADE'); $table->foreign('variable_id')->references('id')->on('service_variables')->onDelete('CASCADE');
}); });

View File

@ -28,12 +28,19 @@ return new class extends Migration
}); });
}); });
Schema::table('api_keys', function (Blueprint $table) { if (Schema::getConnection()->getDriverName() === 'sqlite') {
$table->dropColumn('public'); Schema::table('api_keys', function (Blueprint $table) {
$table->string('secret', 32)->change(); $table->dropColumn('public');
}); $table->char('secret', 32)->change();
$table->renameColumn('secret', 'token');
$table->string('token', 32)->unique()->change();
});
}
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
DB::statement('ALTER TABLE `api_keys` CHANGE `secret` `token` CHAR(32) NOT NULL, ADD UNIQUE INDEX `api_keys_token_unique` (`token`(32))');
}
DB::statement('ALTER TABLE `api_keys` CHANGE `secret` `token` CHAR(32) NOT NULL, ADD UNIQUE INDEX `api_keys_token_unique` (`token`(32))');
} }
/** /**

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
}
$table->foreign('node_id')->references('id')->on('nodes')->onDelete('cascade'); $table->foreign('node_id')->references('id')->on('nodes')->onDelete('cascade');
}); });
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void public function down(): void
{ {
Schema::table('allocations', function (Blueprint $table) { Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign(['node_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
}
$table->foreign('node_id')->references('id')->on('nodes'); $table->foreign('node_id')->references('id')->on('nodes');
}); });

View File

@ -1,6 +1,5 @@
<?php <?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
@ -12,9 +11,11 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
DB::table('settings')->truncate(); Schema::dropIfExists('settings');
Schema::table('settings', function (Blueprint $table) { Schema::create('settings', function (Blueprint $table) {
$table->increments('id')->first(); $table->increments('id');
$table->string('key');
$table->text('value');
}); });
} }

View File

@ -16,7 +16,9 @@ return new class extends Migration
$table->timestamp('last_used_at')->after('memo')->nullable(); $table->timestamp('last_used_at')->after('memo')->nullable();
$table->dropColumn('expires_at'); $table->dropColumn('expires_at');
$table->dropForeign(['user_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['user_id']);
}
}); });
Schema::table('api_keys', function (Blueprint $table) { Schema::table('api_keys', function (Blueprint $table) {
@ -32,7 +34,10 @@ return new class extends Migration
Schema::table('api_keys', function (Blueprint $table) { Schema::table('api_keys', function (Blueprint $table) {
$table->timestamp('expires_at')->after('memo')->nullable(); $table->timestamp('expires_at')->after('memo')->nullable();
$table->dropColumn('last_used_at', 'key_type'); $table->dropColumn('last_used_at', 'key_type');
$table->dropForeign(['user_id']);
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['user_id']);
}
}); });
Schema::table('api_keys', function (Blueprint $table) { Schema::table('api_keys', function (Blueprint $table) {

View File

@ -1,6 +1,5 @@
<?php <?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
@ -12,21 +11,6 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
$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) { Schema::create('backups', function (Blueprint $table) {
$table->bigIncrements('id'); $table->bigIncrements('id');
$table->unsignedInteger('server_id'); $table->unsignedInteger('server_id');

View File

@ -1,6 +1,5 @@
<?php <?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
@ -12,23 +11,9 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
$db = config('database.default'); Schema::table('servers', function (Blueprint $table) {
// Same as in the backups migration, we need to handle that plugin messing with the data structure $table->unsignedInteger('backup_limit')->default(0)->after('database_limit');
// 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');
});
}
} }
/** /**

View File

@ -15,10 +15,6 @@ return new class extends Migration
Schema::table('backups', function (Blueprint $table) { Schema::table('backups', function (Blueprint $table) {
$table->renameColumn('sha256_hash', 'checksum'); $table->renameColumn('sha256_hash', 'checksum');
}); });
Schema::table('backups', function (Blueprint $table) {
DB::update('UPDATE backups SET checksum = CONCAT(\'sha256:\', checksum)');
});
} }
/** /**
@ -29,9 +25,5 @@ return new class extends Migration
Schema::table('backups', function (Blueprint $table) { Schema::table('backups', function (Blueprint $table) {
$table->renameColumn('checksum', 'sha256_hash'); $table->renameColumn('checksum', 'sha256_hash');
}); });
Schema::table('backups', function (Blueprint $table) {
DB::update('UPDATE backups SET sha256_hash = SUBSTRING(sha256_hash, 8)');
});
} }
}; };

View File

@ -12,7 +12,10 @@ return new class extends Migration
public function up(): void public function up(): void
{ {
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['pack_id']); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['pack_id']);
}
$table->dropColumn('pack_id'); $table->dropColumn('pack_id');
}); });
} }

View File

@ -28,12 +28,16 @@ return new class extends Migration
} }
Schema::table('eggs', function (Blueprint $table) { Schema::table('eggs', function (Blueprint $table) {
$table->dropForeign('service_options_nest_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('service_options_nest_id_foreign');
}
$table->dropColumn('nest_id'); $table->dropColumn('nest_id');
}); });
Schema::table('servers', function (Blueprint $table) { Schema::table('servers', function (Blueprint $table) {
$table->dropForeign('servers_nest_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('servers_nest_id_foreign');
}
$table->dropColumn('nest_id'); $table->dropColumn('nest_id');
}); });

View File

@ -27,7 +27,10 @@ return new class extends Migration
} }
Schema::table('nodes', function (Blueprint $table) { Schema::table('nodes', function (Blueprint $table) {
$table->dropForeign('nodes_location_id_foreign'); if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('nodes_location_id_foreign');
}
$table->dropColumn('location_id'); $table->dropColumn('location_id');
}); });