mirror of
https://github.com/pyrohost/pyrodactyl.git
synced 2026-04-06 04:01:58 +02:00
fixes #416
A bug was introduced where creating the contraint for postgres databases was done using "ADD CONTRAINT IF NOT EXISTS" which is not proper syntax
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@@ -11,14 +12,42 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
// Modify the disk column to support rustic adapters
|
||||
$table->enum('disk', ['wings', 's3', 'rustic_local', 'rustic_s3'])->default('wings')->change();
|
||||
switch (DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME)) {
|
||||
case 'mysql':
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
// Modify the disk column to support rustic adapters
|
||||
$table->enum('disk', ['wings', 's3', 'rustic_local', 'rustic_s3'])
|
||||
->default('wings')
|
||||
->change();
|
||||
|
||||
// Add rustic-specific columns
|
||||
$table->string('snapshot_id', 64)->nullable()->after('checksum')->comment('Rustic snapshot ID for rustic backups');
|
||||
});
|
||||
// Add rustic-specific columns
|
||||
$table->string('snapshot_id', 64)
|
||||
->nullable()
|
||||
->after('checksum')
|
||||
->comment('Rustic snapshot ID for rustic backups');
|
||||
});
|
||||
break;
|
||||
|
||||
case 'pgsql':
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
// Use string + enforce values via CHECK constraint
|
||||
$table->string('disk')->default('wings')->change();
|
||||
|
||||
// Add the check constraint
|
||||
DB::statement("
|
||||
ALTER TABLE backups
|
||||
ADD CONSTRAINT backups_disk_check
|
||||
CHECK (disk IN ('wings', 's3', 'rustic_local', 'rustic_s3'))
|
||||
");
|
||||
|
||||
// Add rustic-specific column
|
||||
$table->string('snapshot_id', 64)
|
||||
->nullable()
|
||||
->after('checksum')
|
||||
->comment('Rustic snapshot ID for rustic backups');
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,13 +55,35 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
// Revert disk column to original enum values
|
||||
$table->enum('disk', ['wings', 's3'])->default('wings')->change();
|
||||
switch (DB::connection()->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME)) {
|
||||
case 'mysql':
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
// Revert disk column to original enum values
|
||||
$table->enum('disk', ['wings', 's3'])->default('wings')->change();
|
||||
// Drop rustic-specific columns
|
||||
$table->dropColumn('snapshot_id');
|
||||
});
|
||||
break;
|
||||
|
||||
// Drop rustic-specific columns
|
||||
$table->dropColumn('snapshot_id');
|
||||
});
|
||||
case 'pgsql':
|
||||
Schema::table('backups', function (Blueprint $table) {
|
||||
// Drop the check constraint first
|
||||
DB::statement("ALTER TABLE backups DROP CONSTRAINT backups_disk_check");
|
||||
|
||||
// Revert disk to string with original allowed values
|
||||
$table->string('disk')->default('wings')->change();
|
||||
|
||||
// Re-add original constraint
|
||||
DB::statement("
|
||||
ALTER TABLE backups
|
||||
ADD CONSTRAINT IF NOT EXISTS backups_disk_check
|
||||
CHECK (disk IN ('wings', 's3'))
|
||||
");
|
||||
|
||||
// Drop rustic-specific column
|
||||
$table->dropColumn('snapshot_id');
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user