Fix SERVICE_FQDN_DB error by preventing fqdn access on ServiceDatabase

ServiceDatabase doesn't have an fqdn column - only ServiceApplication does.
The parser was attempting to read/write fqdn on both types, causing SQL
errors when SERVICE_FQDN_* or SERVICE_URL_* variables were used with database
services. Now it only persists fqdn to ServiceApplication while still
generating the environment variable values for databases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai 2025-11-21 12:48:04 +01:00
parent 8af6339695
commit b62eece93e

View file

@ -1595,7 +1595,11 @@ function serviceParser(Service $resource): Collection
$urlFor = $parsed['service_name'];
}
$port = $parsed['port'];
if (blank($savedService->fqdn)) {
// Only ServiceApplication has fqdn column, ServiceDatabase does not
$isServiceApplication = $savedService instanceof ServiceApplication;
if ($isServiceApplication && blank($savedService->fqdn)) {
if ($fqdnFor) {
$fqdn = generateFqdn(server: $server, random: "$fqdnFor-$uuid", parserVersion: $resource->compose_parsing_version);
} else {
@ -1606,9 +1610,21 @@ function serviceParser(Service $resource): Collection
} else {
$url = generateUrl($server, "{$savedService->name}-$uuid");
}
} else {
} elseif ($isServiceApplication) {
$fqdn = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value();
$url = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value();
} else {
// For ServiceDatabase, generate fqdn/url without saving to the model
if ($fqdnFor) {
$fqdn = generateFqdn(server: $server, random: "$fqdnFor-$uuid", parserVersion: $resource->compose_parsing_version);
} else {
$fqdn = generateFqdn(server: $server, random: "{$savedService->name}-$uuid", parserVersion: $resource->compose_parsing_version);
}
if ($urlFor) {
$url = generateUrl($server, "$urlFor-$uuid");
} else {
$url = generateUrl($server, "{$savedService->name}-$uuid");
}
}
if ($value && get_class($value) === \Illuminate\Support\Stringable::class && $value->startsWith('/')) {
@ -1626,7 +1642,8 @@ function serviceParser(Service $resource): Collection
if ($url && $port) {
$urlWithPort = "$url:$port";
}
if (is_null($savedService->fqdn)) {
// Only save fqdn to ServiceApplication, not ServiceDatabase
if ($isServiceApplication && is_null($savedService->fqdn)) {
if ((int) $resource->compose_parsing_version >= 5 && version_compare(config('constants.coolify.version'), '4.0.0-beta.420.7', '>=')) {
if ($fqdnFor) {
$savedService->fqdn = $fqdnWithPort;