fix: redis database user and password

This commit is contained in:
Andras Bacsai
2024-10-21 12:13:42 +02:00
parent e8c7d7f972
commit bf7b0f9e06
7 changed files with 77 additions and 95 deletions

View File

@@ -1,22 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('standalone_redis', function (Blueprint $table) {
$table->string('redis_username')->default('redis')->after('description');
});
}
public function down(): void
{
Schema::table('standalone_redis', function (Blueprint $table) {
$table->dropColumn('redis_username');
});
}
};

View File

@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
class EncryptExistingRedisPasswords extends Migration
class MoveRedisPasswordToEnvs extends Migration
{
/**
* Run the migrations.
@@ -14,13 +14,15 @@ class EncryptExistingRedisPasswords extends Migration
try {
DB::table('standalone_redis')->chunkById(100, function ($redisInstances) {
foreach ($redisInstances as $redis) {
DB::table('standalone_redis')
->where('id', $redis->id)
->update(['redis_password' => Crypt::encryptString($redis->redis_password)]);
$redis->runtime_environment_variables()->firstOrCreate([
'key' => 'REDIS_PASSWORD',
'value' => $redis->redis_password,
]);
}
});
DB::statement('ALTER TABLE standalone_redis DROP COLUMN redis_password');
} catch (\Exception $e) {
echo 'Encrypting Redis passwords failed.';
echo 'Moving Redis passwords to envs failed.';
echo $e->getMessage();
}
}