Add migrations to handle cascade deletions for servers and users
This commit is contained in:
parent
2588c25b0b
commit
8953f83f87
|
@ -30,6 +30,7 @@ use Carbon;
|
||||||
use Request;
|
use Request;
|
||||||
use Pterodactyl\Models\APIKey;
|
use Pterodactyl\Models\APIKey;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Pterodactyl\Services\ApiKeyService;
|
||||||
|
|
||||||
class MacroServiceProvider extends ServiceProvider
|
class MacroServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
@ -60,7 +61,7 @@ class MacroServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
$parts = explode('.', Request::bearerToken());
|
$parts = explode('.', Request::bearerToken());
|
||||||
|
|
||||||
if (count($parts) === 2 && strlen($parts[0]) === APIKey::PUBLIC_KEY_LEN) {
|
if (count($parts) === 2 && strlen($parts[0]) === ApiKeyService::PUB_CRYPTO_BYTES * 2) {
|
||||||
// Because the key itself isn't changing frequently, we simply cache this for
|
// Because the key itself isn't changing frequently, we simply cache this for
|
||||||
// 15 minutes to speed up the API and keep requests flowing.
|
// 15 minutes to speed up the API and keep requests flowing.
|
||||||
return Cache::tags([
|
return Cache::tags([
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class ChangeUserPermissionsToDeleteOnUserDeletion extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('permissions', function (Blueprint $table) {
|
||||||
|
$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']);
|
||||||
|
|
||||||
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||||
|
$table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('subusers', function (Blueprint $table) {
|
||||||
|
$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']);
|
||||||
|
|
||||||
|
$table->foreign('subuser_id')->references('id')->on('subusers');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class SetAllocationToReferenceNullOnServerDelete extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('allocations', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['server_id']);
|
||||||
|
|
||||||
|
$table->foreign('server_id')->references('id')->on('servers')->onDelete('set null');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('allocations', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['server_id']);
|
||||||
|
|
||||||
|
$table->foreign('server_id')->references('id')->on('servers');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CascadeDeletionWhenAServerOrVariableIsDeleted extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('server_variables', function (Blueprint $table) {
|
||||||
|
$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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('server_variables', function (Blueprint $table) {
|
||||||
|
$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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue