PostgreSQL Support (#4486)

Co-authored-by: Matthew Penner <matthew@pterodactyl.io>
This commit is contained in:
Lance Pioch 2022-11-25 15:29:04 -05:00 committed by GitHub
parent 21613fa602
commit 3bf5a71802
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
223 changed files with 912 additions and 1052 deletions

View file

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Schema;
@ -12,13 +13,13 @@ class MigratePubPrivFormatToSingleKey extends Migration
/**
* Run the migrations.
*/
public function up()
public function up(): void
{
DB::transaction(function () {
DB::table('api_keys')->get()->each(function ($item) {
try {
$decrypted = Crypt::decrypt($item->secret);
} catch (DecryptException $exception) {
} catch (DecryptException) {
$decrypted = str_random(32);
} finally {
DB::table('api_keys')->where('id', $item->id)->update([
@ -30,27 +31,41 @@ class MigratePubPrivFormatToSingleKey extends Migration
Schema::table('api_keys', function (Blueprint $table) {
$table->dropColumn('public');
$table->string('secret', 32)->change();
$table->renameColumn('secret', 'token');
});
DB::statement('ALTER TABLE `api_keys` CHANGE `secret` `token` CHAR(32) NOT NULL, ADD UNIQUE INDEX `api_keys_token_unique` (`token`(32))');
Schema::table('api_keys', function (Blueprint $table) {
$table->char('token', 32)->change();
$table->unique('token');
});
}
/**
* Reverse the migrations.
*/
public function down()
public function down(): void
{
DB::statement('ALTER TABLE `api_keys` CHANGE `token` `secret` TEXT, DROP INDEX `api_keys_token_unique`');
Schema::table('api_keys', function (Blueprint $table) {
$table->dropUnique(['token']);
$table->renameColumn('token', 'secret');
});
Schema::table('api_keys', function (Blueprint $table) {
$table->dropUnique('token');
$table->text('token')->change();
});
Schema::table('api_keys', function (Blueprint $table) {
$table->renameColumn('token', 'secret');
$table->text('secret')->nullable()->change();
$table->char('public', 16)->after('user_id');
});
DB::transaction(function () {
DB::table('api_keys')->get()->each(function ($item) {
DB::table('api_keys')->where('id', $item->id)->update([
'public' => str_random(16),
'public' => Str::random(16),
'secret' => Crypt::encrypt($item->secret),
]);
});