fix: migrations
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class EncryptExistingPrivateKeys extends Migration
|
class EncryptExistingPrivateKeys extends Migration
|
||||||
{
|
{
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
DB::table('private_keys')->chunkById(100, function ($keys) {
|
DB::table('private_keys')->chunkById(100, function ($keys) {
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
DB::table('private_keys')
|
DB::table('private_keys')
|
||||||
@@ -15,5 +16,10 @@ class EncryptExistingPrivateKeys extends Migration
|
|||||||
->update(['private_key' => Crypt::encryptString($key->private_key)]);
|
->update(['private_key' => Crypt::encryptString($key->private_key)]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo 'Encrypting private keys failed.';
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
use App\Models\PrivateKey;
|
use App\Models\PrivateKey;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class AddSshKeyFingerprintToPrivateKeysTable extends Migration
|
class AddSshKeyFingerprintToPrivateKeysTable extends Migration
|
||||||
@@ -13,13 +14,20 @@ class AddSshKeyFingerprintToPrivateKeysTable extends Migration
|
|||||||
$table->string('fingerprint')->after('private_key')->nullable();
|
$table->string('fingerprint')->after('private_key')->nullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
PrivateKey::whereNull('fingerprint')->each(function ($key) {
|
try {
|
||||||
|
DB::table('private_keys')->chunkById(100, function ($keys) {
|
||||||
|
foreach ($keys as $key) {
|
||||||
$fingerprint = PrivateKey::generateFingerprint($key->private_key);
|
$fingerprint = PrivateKey::generateFingerprint($key->private_key);
|
||||||
if ($fingerprint) {
|
if ($fingerprint) {
|
||||||
$key->fingerprint = $fingerprint;
|
$key->fingerprint = $fingerprint;
|
||||||
$key->save();
|
$key->save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo 'Generating fingerprints failed.';
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down()
|
public function down()
|
||||||
|
|||||||
Reference in New Issue
Block a user