diff --git a/database/migrations/2024_09_16_111428_encrypt_existing_private_keys.php b/database/migrations/2024_09_16_111428_encrypt_existing_private_keys.php index e2297cf37..19274ad9b 100644 --- a/database/migrations/2024_09_16_111428_encrypt_existing_private_keys.php +++ b/database/migrations/2024_09_16_111428_encrypt_existing_private_keys.php @@ -1,19 +1,25 @@ 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(); + } + } } diff --git a/database/migrations/2024_09_17_111226_add_ssh_key_fingerprint_to_private_keys_table.php b/database/migrations/2024_09_17_111226_add_ssh_key_fingerprint_to_private_keys_table.php index f16eccb5c..dfce5682a 100644 --- a/database/migrations/2024_09_17_111226_add_ssh_key_fingerprint_to_private_keys_table.php +++ b/database/migrations/2024_09_17_111226_add_ssh_key_fingerprint_to_private_keys_table.php @@ -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()