mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-12 22:14:26 +00:00
fix: predefined server env were not generated for existing servers
This commit is contained in:
1 parent
09e14d2f51
commit
82b19e5921
2 files changed
+69
-1
No files matched your search
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Add predefined server variables to all existing servers
|
||||
$servers = DB::table('servers')->get();
|
||||
|
||||
foreach ($servers as $server) {
|
||||
// Check if COOLIFY_SERVER_UUID already exists
|
||||
$uuidExists = DB::table('shared_environment_variables')
|
||||
->where('type', 'server')
|
||||
->where('server_id', $server->id)
|
||||
->where('key', 'COOLIFY_SERVER_UUID')
|
||||
->exists();
|
||||
|
||||
if (!$uuidExists) {
|
||||
DB::table('shared_environment_variables')->insert([
|
||||
'key' => 'COOLIFY_SERVER_UUID',
|
||||
'value' => $server->uuid,
|
||||
'type' => 'server',
|
||||
'server_id' => $server->id,
|
||||
'team_id' => $server->team_id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
// Check if COOLIFY_SERVER_NAME already exists
|
||||
$nameExists = DB::table('shared_environment_variables')
|
||||
->where('type', 'server')
|
||||
->where('server_id', $server->id)
|
||||
->where('key', 'COOLIFY_SERVER_NAME')
|
||||
->exists();
|
||||
|
||||
if (!$nameExists) {
|
||||
DB::table('shared_environment_variables')->insert([
|
||||
'key' => 'COOLIFY_SERVER_NAME',
|
||||
'value' => $server->name,
|
||||
'type' => 'server',
|
||||
'server_id' => $server->id,
|
||||
'team_id' => $server->team_id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Remove predefined server variables
|
||||
DB::table('shared_environment_variables')
|
||||
->where('type', 'server')
|
||||
->whereIn('key', ['COOLIFY_SERVER_UUID', 'COOLIFY_SERVER_NAME'])
|
||||
->delete();
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user