refactor: Optimize UUID generation for cloud provider tokens using chunked processing

This commit is contained in:
Andras Bacsai
2025-12-11 12:08:12 +01:00
parent 1b4705220d
commit cf4985c596
3 changed files with 133 additions and 17 deletions

View File

@@ -17,13 +17,16 @@ return new class extends Migration
$table->string('uuid')->nullable()->unique()->after('id');
});
// Generate UUIDs for existing records
$tokens = DB::table('cloud_provider_tokens')->whereNull('uuid')->get();
foreach ($tokens as $token) {
DB::table('cloud_provider_tokens')
->where('id', $token->id)
->update(['uuid' => (string) new Cuid2]);
}
// Generate UUIDs for existing records using chunked processing
DB::table('cloud_provider_tokens')
->whereNull('uuid')
->chunkById(500, function ($tokens) {
foreach ($tokens as $token) {
DB::table('cloud_provider_tokens')
->where('id', $token->id)
->update(['uuid' => (string) new Cuid2]);
}
});
// Make uuid non-nullable after filling in values
Schema::table('cloud_provider_tokens', function (Blueprint $table) {