Files
coolify/app/Traits/ExecutesDatabaseStartCommands.php
e3d4411ff2 chore: merge main into release/v4.5 (#12192)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Furox <177975472+Furox-Art@users.noreply.github.com>
Co-authored-by: johandenhollander <johan.den.hollander@finalist.nl>
Co-authored-by: João Cruz <161638790+SrJooJ@users.noreply.github.com>
Co-authored-by: Saim Hashmi <hashmisaim037@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-10-18 23:43:20 +02:00

50 lines
1.9 KiB
PHP

<?php
namespace App\Traits;
use App\Services\DatabaseStartCommandExecutor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Spatie\Activitylog\Models\Activity;
trait ExecutesDatabaseStartCommands
{
private function executeDatabaseStartCommands(array $commands, Model $database, ?Activity $activity = null): Activity
{
if ($activity) {
return app(DatabaseStartCommandExecutor::class)->execute($commands, $database, $activity);
}
return remote_process($commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged', queue: deployment_queue());
}
/**
* Whether a `KEY=value` list already defines the exact key (not just a key or value containing it).
*
* @param Collection<int, string> $environmentVariables
*/
private function hasEnvironmentVariable(Collection $environmentVariables, string $key): bool
{
return $environmentVariables->contains(fn ($variable) => str($variable)->before('=')->value() === $key);
}
/**
* Adds the Coolify variables that applications and services also get. A key that the user
* defines wins.
*
* @param Collection<int, string> $environmentVariables
*/
private function addCoolifyEnvironmentVariables(Collection $environmentVariables): void
{
$definedKeys = $environmentVariables->map(fn ($variable) => str($variable)->before('=')->value());
$coolifyVariables = collect([
'COOLIFY_RESOURCE_UUID' => $this->database->uuid,
'COOLIFY_CONTAINER_NAME' => $this->database->uuid,
])->except($definedKeys->all())->merge(coolifyDefaultEnvironmentVariables($this->database, $definedKeys));
foreach ($coolifyVariables as $key => $value) {
$environmentVariables->push($key.'='.escapeDollarSign($value));
}
}
}