2017-02-09 23:44:07 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-12 20:10:39 +00:00
|
|
|
use Pterodactyl\Models\Subuser;
|
|
|
|
use Pterodactyl\Models\Permission;
|
2017-02-09 23:44:07 +00:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
|
|
|
|
class SetupPermissionsPivotTable extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*/
|
2022-11-25 20:29:04 +00:00
|
|
|
public function up(): void
|
2017-02-09 23:44:07 +00:00
|
|
|
{
|
|
|
|
Schema::table('permissions', function (Blueprint $table) {
|
|
|
|
$table->unsignedInteger('subuser_id')->after('id');
|
|
|
|
});
|
|
|
|
|
|
|
|
DB::transaction(function () {
|
2017-02-12 20:10:39 +00:00
|
|
|
foreach (Subuser::all() as &$subuser) {
|
2022-11-25 20:29:04 +00:00
|
|
|
Permission::query()->where('user_id', $subuser->user_id)->where('server_id', $subuser->server_id)->update([
|
2017-02-09 23:44:07 +00:00
|
|
|
'subuser_id' => $subuser->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Schema::table('permissions', function (Blueprint $table) {
|
2022-11-25 20:29:04 +00:00
|
|
|
$table->dropForeign(['server_id']);
|
|
|
|
$table->dropForeign(['user_id']);
|
2017-02-09 23:44:07 +00:00
|
|
|
|
|
|
|
$table->dropColumn('server_id');
|
|
|
|
$table->dropColumn('user_id');
|
2017-02-10 00:38:54 +00:00
|
|
|
$table->dropColumn('created_at');
|
|
|
|
$table->dropColumn('updated_at');
|
2017-02-09 23:44:07 +00:00
|
|
|
$table->foreign('subuser_id')->references('id')->on('subusers');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*/
|
2022-11-25 20:29:04 +00:00
|
|
|
public function down(): void
|
2017-02-09 23:44:07 +00:00
|
|
|
{
|
|
|
|
Schema::table('permissions', function (Blueprint $table) {
|
|
|
|
$table->unsignedInteger('server_id')->after('subuser_id');
|
|
|
|
$table->unsignedInteger('user_id')->after('server_id');
|
2017-02-10 00:38:54 +00:00
|
|
|
$table->timestamps();
|
2017-02-09 23:44:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
DB::transaction(function () {
|
2017-02-12 20:10:39 +00:00
|
|
|
foreach (Subuser::all() as &$subuser) {
|
2022-11-25 20:29:04 +00:00
|
|
|
Permission::query()->where('subuser_id', $subuser->id)->update([
|
2017-02-09 23:44:07 +00:00
|
|
|
'user_id' => $subuser->user_id,
|
|
|
|
'server_id' => $subuser->server_id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Schema::table('permissions', function (Blueprint $table) {
|
2022-11-25 20:29:04 +00:00
|
|
|
$table->dropForeign(['subuser_id']);
|
|
|
|
$table->dropIndex(['subuser_id']);
|
2017-02-09 23:44:07 +00:00
|
|
|
$table->dropColumn('subuser_id');
|
|
|
|
|
|
|
|
$table->foreign('server_id')->references('id')->on('servers');
|
|
|
|
$table->foreign('user_id')->references('id')->on('users');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|