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;
use App\Filament\Resources\EggResource;
use App\Models\User;
use Filament\Resources\Pages\CreateRecord;
use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
use Filament\Forms;

View File

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

View File

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

View File

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

View File

@ -11,7 +11,9 @@ return new class extends Migration
*/
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) {
$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');
});
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
{
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) {
$table->foreign('location')->references('id')->on('locations');
@ -28,6 +30,8 @@ return new class extends Migration
$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
{
DB::statement('ALTER TABLE server_variables
MODIFY COLUMN server_id INT(10) UNSIGNED NULL,
MODIFY COLUMN variable_id INT(10) UNSIGNED NOT NULL
');
Schema::table('server_variables', function (Blueprint $table) {
$table->unsignedInteger('server_id')->change();
$table->unsignedInteger('variable_id')->change();
});
Schema::table('server_variables', function (Blueprint $table) {
$table->foreign('server_id')->references('id')->on('servers');
@ -32,9 +32,10 @@ return new class extends Migration
$table->dropForeign(['variable_id']);
});
DB::statement('ALTER TABLE server_variables
MODIFY COLUMN server_id MEDIUMINT(8) UNSIGNED NULL,
MODIFY COLUMN variable_id MEDIUMINT(8) UNSIGNED NOT NULL
');
Schema::table('server_variables', function (Blueprint $table) {
$table->unsignedMediumInteger('server_id')->change();
$table->unsignedMediumInteger('variable_id')->change();
});
}
};

View File

@ -11,7 +11,9 @@ return new class extends Migration
*/
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) {
$table->foreign('parent_service')->references('id')->on('services');
@ -28,6 +30,8 @@ return new class extends Migration
$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
{
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) {
$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');
});
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
{
Schema::table('servers', function (Blueprint $table) {
$table->dropForeign('servers_node_foreign');
$table->dropForeign('servers_owner_foreign');
$table->dropForeign('servers_allocation_foreign');
$table->dropForeign('servers_service_foreign');
$table->dropForeign('servers_option_foreign');
$table->dropForeign('servers_pack_foreign');
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('servers_node_foreign');
$table->dropForeign('servers_owner_foreign');
$table->dropForeign('servers_allocation_foreign');
$table->dropForeign('servers_service_foreign');
$table->dropForeign('servers_option_foreign');
$table->dropForeign('servers_pack_foreign');
$table->dropIndex('servers_node_foreign');
$table->dropIndex('servers_owner_foreign');
$table->dropIndex('servers_allocation_foreign');
$table->dropIndex('servers_service_foreign');
$table->dropIndex('servers_option_foreign');
$table->dropIndex('servers_pack_foreign');
$table->dropIndex('servers_node_foreign');
$table->dropIndex('servers_owner_foreign');
$table->dropIndex('servers_allocation_foreign');
$table->dropIndex('servers_service_foreign');
$table->dropIndex('servers_option_foreign');
$table->dropIndex('servers_pack_foreign');
}
$table->renameColumn('node', 'node_id');
$table->renameColumn('owner', 'owner_id');
@ -50,11 +52,13 @@ return new class extends Migration
public function down(): void
{
Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['node_id']);
$table->dropForeign(['owner_id']);
$table->dropForeign(['allocation_id']);
$table->dropForeign(['service_id']);
$table->dropForeign(['option_id']);
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['node_id']);
$table->dropForeign(['owner_id']);
$table->dropForeign(['allocation_id']);
$table->dropForeign(['service_id']);
$table->dropForeign(['option_id']);
}
$table->renameColumn('node_id', 'node');
$table->renameColumn('owner_id', 'owner');

View File

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

View File

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

View File

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

View File

@ -12,8 +12,10 @@ return new class extends Migration
public function up(): void
{
Schema::table('service_packs', function (Blueprint $table) {
$table->dropForeign('service_packs_option_foreign');
$table->dropIndex('service_packs_option_foreign');
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('service_packs_option_foreign');
$table->dropIndex('service_packs_option_foreign');
}
$table->renameColumn('option', 'option_id');
$table->foreign('option_id')->references('id')->on('service_options');
@ -26,8 +28,10 @@ return new class extends Migration
public function down(): void
{
Schema::table('service_packs', function (Blueprint $table) {
$table->dropForeign('service_packs_option_id_foreign');
$table->dropIndex('service_packs_option_id_foreign');
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('service_packs_option_id_foreign');
$table->dropIndex('service_packs_option_id_foreign');
}
$table->renameColumn('option_id', 'option');
$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) {
$table->dropForeign('permissions_server_id_foreign');
$table->dropIndex('permissions_server_id_foreign');
$table->dropForeign('permissions_user_id_foreign');
$table->dropIndex('permissions_user_id_foreign');
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('permissions_server_id_foreign');
$table->dropIndex('permissions_server_id_foreign');
$table->dropForeign('permissions_user_id_foreign');
$table->dropIndex('permissions_user_id_foreign');
}
$table->dropColumn('server_id');
$table->dropColumn('user_id');
@ -60,8 +62,10 @@ return new class extends Migration
});
Schema::table('permissions', function (Blueprint $table) {
$table->dropForeign('permissions_subuser_id_foreign');
$table->dropIndex('permissions_subuser_id_foreign');
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign('permissions_subuser_id_foreign');
$table->dropIndex('permissions_subuser_id_foreign');
}
$table->dropColumn('subuser_id');
$table->foreign('server_id')->references('id')->on('servers');

View File

@ -12,7 +12,10 @@ return new class extends Migration
public function up(): void
{
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->foreign('user_id')->references('id')->on('users');
@ -25,7 +28,10 @@ return new class extends Migration
public function down(): void
{
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->foreign('user')->references('id')->on('users');

View File

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

View File

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

View File

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

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
@ -26,7 +28,9 @@ return new class extends Migration
public function down(): void
{
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');

View File

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

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void
{
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');
});

View File

@ -12,14 +12,18 @@ return new class extends Migration
public function up(): void
{
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');
});
Schema::table('subusers', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['server_id']);
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['user_id']);
$table->dropForeign(['server_id']);
}
$table->foreign('user_id')->references('id')->on('users')->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
{
Schema::table('subusers', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['server_id']);
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['user_id']);
$table->dropForeign(['server_id']);
}
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('server_id')->references('id')->on('servers');
});
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');
});

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void
{
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');
});

View File

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

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});
}
@ -23,7 +25,9 @@ return new class extends Migration
public function down(): void
{
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');
});
}

View File

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

View File

@ -22,7 +22,9 @@ return new class extends Migration
public function down(): void
{
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->foreign('node_id')->references('id')->on('nodes');
});

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void
{
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');
});

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});
@ -24,8 +26,9 @@ return new class extends Migration
public function down(): void
{
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');
});
}

View File

@ -12,7 +12,9 @@ return new class extends Migration
public function up(): void
{
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');
});
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void
{
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');
});

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
@ -15,14 +16,18 @@ return new class extends Migration
Schema::rename('services', 'nests');
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->foreign('nest_id')->references('id')->on('nests');
});
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->foreign('nest_id')->references('id')->on('nests')->onDelete('CASCADE');
@ -41,14 +46,18 @@ return new class extends Migration
Schema::rename('nests', 'services');
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->foreign('service_id')->references('id')->on('services');
});
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->foreign('service_id')->references('id')->on('services')->onDelete('CASCADE');

View File

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

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
@ -15,7 +16,9 @@ return new class extends Migration
Schema::rename('service_variables', 'egg_variables');
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');
});
@ -33,7 +36,9 @@ return new class extends Migration
Schema::rename('egg_variables', 'service_variables');
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');
});

View File

@ -28,12 +28,19 @@ return new class extends Migration
});
});
Schema::table('api_keys', function (Blueprint $table) {
$table->dropColumn('public');
$table->string('secret', 32)->change();
});
if (Schema::getConnection()->getDriverName() === 'sqlite') {
Schema::table('api_keys', function (Blueprint $table) {
$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
{
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');
});
@ -24,7 +26,9 @@ return new class extends Migration
public function down(): void
{
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');
});

View File

@ -1,6 +1,5 @@
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
@ -12,9 +11,11 @@ return new class extends Migration
*/
public function up(): void
{
DB::table('settings')->truncate();
Schema::table('settings', function (Blueprint $table) {
$table->increments('id')->first();
Schema::dropIfExists('settings');
Schema::create('settings', function (Blueprint $table) {
$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->dropColumn('expires_at');
$table->dropForeign(['user_id']);
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['user_id']);
}
});
Schema::table('api_keys', function (Blueprint $table) {
@ -32,7 +34,10 @@ return new class extends Migration
Schema::table('api_keys', function (Blueprint $table) {
$table->timestamp('expires_at')->after('memo')->nullable();
$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) {

View File

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

View File

@ -1,6 +1,5 @@
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
@ -12,23 +11,9 @@ return new class extends Migration
*/
public function up(): void
{
$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');
});
}
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) {
$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) {
$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
{
Schema::table('servers', function (Blueprint $table) {
$table->dropForeign(['pack_id']);
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
$table->dropForeign(['pack_id']);
}
$table->dropColumn('pack_id');
});
}

View File

@ -28,12 +28,16 @@ return new class extends Migration
}
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');
});
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');
});

View File

@ -27,7 +27,10 @@ return new class extends Migration
}
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');
});