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