An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor: replace direct SslCertificate queries with server relationship methods for consistency
Andras Bacsaif4e5c195fe8e
diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.phpindex 38ad99d2e6..0db73ba07b 100644--- a/app/Actions/Database/StartDragonfly.php+++ b/app/Actions/Database/StartDragonfly.php@@ -55,11 +55,11 @@ class StartDragonfly$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.phpindex 59bcd4123b..2908eb9c11 100644--- a/app/Actions/Database/StartKeydb.php+++ b/app/Actions/Database/StartKeydb.php@@ -56,11 +56,11 @@ class StartKeydb$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.phpindex 13dba4b43c..11b424ff8f 100644--- a/app/Actions/Database/StartMariadb.php+++ b/app/Actions/Database/StartMariadb.php@@ -57,11 +57,11 @@ class StartMariadb$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.phpindex 870b5b7e5a..0bf6ab253f 100644--- a/app/Actions/Database/StartMongodb.php+++ b/app/Actions/Database/StartMongodb.php@@ -61,11 +61,11 @@ class StartMongodb$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.phpindex 5d5611e07a..bf81d01abe 100644--- a/app/Actions/Database/StartMysql.php+++ b/app/Actions/Database/StartMysql.php@@ -57,11 +57,11 @@ class StartMysql$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.phpindex 38d46b3c15..6cdf32e270 100644--- a/app/Actions/Database/StartPostgresql.php+++ b/app/Actions/Database/StartPostgresql.php@@ -62,11 +62,11 @@ class StartPostgresql$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.phpindex 68a1f3fe39..c040ec3913 100644--- a/app/Actions/Database/StartRedis.php+++ b/app/Actions/Database/StartRedis.php@@ -56,11 +56,11 @@ class StartRedis$this->commands[] = "mkdir -p $this->configuration_dir/ssl";$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Actions/Server/InstallDocker.php b/app/Actions/Server/InstallDocker.phpindex 5410b1cbd0..10589c8b9f 100644--- a/app/Actions/Server/InstallDocker.php+++ b/app/Actions/Server/InstallDocker.php@@ -4,7 +4,6 @@ namespace App\Actions\Server;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneDocker;use Lorisleiva\Actions\Concerns\AsAction;@@ -20,7 +19,7 @@ class InstallDockerthrow new \Exception('Server OS type is not supported for automated installation. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://coolify.io/docs/installation#manually">documentation</a>.');}- if (! SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->exists()) {+ if (! $server->sslCertificates()->where('is_ca_certificate', true)->exists()) {$serverCert = SslHelper::generateSslCertificate(commonName: 'Coolify CA Certificate',serverId: $server->id,diff --git a/app/Jobs/RegenerateSslCertJob.php b/app/Jobs/RegenerateSslCertJob.phpindex cf598c75cb..c0284e1ee9 100644--- a/app/Jobs/RegenerateSslCertJob.php+++ b/app/Jobs/RegenerateSslCertJob.php@@ -45,7 +45,7 @@ class RegenerateSslCertJob implements ShouldQueue$query->cursor()->each(function ($certificate) use ($regenerated) {try {- $caCert = SslCertificate::where('server_id', $certificate->server_id)+ $caCert = $certificate->server->sslCertificates()->where('is_ca_certificate', true)->first();diff --git a/app/Livewire/Project/Database/Dragonfly/General.php b/app/Livewire/Project/Database/Dragonfly/General.phpindex fabbc7cb4e..4b93e69d75 100644--- a/app/Livewire/Project/Database/Dragonfly/General.php+++ b/app/Livewire/Project/Database/Dragonfly/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneDragonfly;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -249,13 +248,13 @@ class General extends Component$server = $this->database->destination->server;- $caCert = SslCertificate::where('server_id', $server->id)+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $caCert) {$server->generateCaCertificate();- $caCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $caCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();}if (! $caCert) {diff --git a/app/Livewire/Project/Database/Keydb/General.php b/app/Livewire/Project/Database/Keydb/General.phpindex 7502d001de..91952533fc 100644--- a/app/Livewire/Project/Database/Keydb/General.php+++ b/app/Livewire/Project/Database/Keydb/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneKeydb;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -255,7 +254,7 @@ class General extends Componentreturn;}- $caCert = SslCertificate::where('server_id', $existingCert->server_id)+ $caCert = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();diff --git a/app/Livewire/Project/Database/Mariadb/General.php b/app/Livewire/Project/Database/Mariadb/General.phpindex c82c4538f7..3ec6a99548 100644--- a/app/Livewire/Project/Database/Mariadb/General.php+++ b/app/Livewire/Project/Database/Mariadb/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneMariadb;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -207,7 +206,7 @@ class General extends Componentreturn;}- $caCert = SslCertificate::where('server_id', $existingCert->server_id)->where('is_ca_certificate', true)->first();+ $caCert = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();SslHelper::generateSslCertificate(commonName: $existingCert->common_name,diff --git a/app/Livewire/Project/Database/Mongodb/General.php b/app/Livewire/Project/Database/Mongodb/General.phpindex 4fbc454376..be52cfa7a3 100644--- a/app/Livewire/Project/Database/Mongodb/General.php+++ b/app/Livewire/Project/Database/Mongodb/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneMongodb;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -215,7 +214,7 @@ class General extends Componentreturn;}- $caCert = SslCertificate::where('server_id', $existingCert->server_id)->where('is_ca_certificate', true)->first();+ $caCert = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();SslHelper::generateSslCertificate(commonName: $existingCert->common_name,diff --git a/app/Livewire/Project/Database/Mysql/General.php b/app/Livewire/Project/Database/Mysql/General.phpindex ada1b3a2c0..e6b0ead243 100644--- a/app/Livewire/Project/Database/Mysql/General.php+++ b/app/Livewire/Project/Database/Mysql/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneMysql;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -215,7 +214,7 @@ class General extends Componentreturn;}- $caCert = SslCertificate::where('server_id', $existingCert->server_id)->where('is_ca_certificate', true)->first();+ $caCert = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();SslHelper::generateSslCertificate(commonName: $existingCert->common_name,diff --git a/app/Livewire/Project/Database/Postgresql/General.php b/app/Livewire/Project/Database/Postgresql/General.phpindex 2d37620b99..06c16a658c 100644--- a/app/Livewire/Project/Database/Postgresql/General.php+++ b/app/Livewire/Project/Database/Postgresql/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandalonePostgresql;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -169,7 +168,7 @@ class General extends Componentreturn;}- $caCert = SslCertificate::where('server_id', $existingCert->server_id)->where('is_ca_certificate', true)->first();+ $caCert = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();SslHelper::generateSslCertificate(commonName: $existingCert->common_name,diff --git a/app/Livewire/Project/Database/Redis/General.php b/app/Livewire/Project/Database/Redis/General.phpindex 1eb4f5c8d4..4cb93e8362 100644--- a/app/Livewire/Project/Database/Redis/General.php+++ b/app/Livewire/Project/Database/Redis/General.php@@ -6,7 +6,6 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use App\Models\StandaloneRedis;use App\Support\ValidationPatterns;use Carbon\Carbon;@@ -209,7 +208,7 @@ class General extends Componentreturn;}- $caCert = SslCertificate::where('server_id', $existingCert->server_id)->where('is_ca_certificate', true)->first();+ $caCert = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();SslHelper::generateSslCertificate(commonName: $existingCert->commonName,diff --git a/app/Livewire/Server/CaCertificate/Show.php b/app/Livewire/Server/CaCertificate/Show.phpindex 039b5f71dc..c929d9b3d5 100644--- a/app/Livewire/Server/CaCertificate/Show.php+++ b/app/Livewire/Server/CaCertificate/Show.php@@ -39,7 +39,7 @@ class Show extends Componentpublic function loadCaCertificate(){- $this->caCertificate = SslCertificate::where('server_id', $this->server->id)->where('is_ca_certificate', true)->first();+ $this->caCertificate = $this->server->sslCertificates()->where('is_ca_certificate', true)->first();if ($this->caCertificate) {$this->certificateContent = $this->caCertificate->ssl_certificate;diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 92111f0f07..e39526949a 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -1342,7 +1342,7 @@ $schema://$host {isCaCertificate: true,validityDays: 10 * 365);- $caCertificate = SslCertificate::where('server_id', $this->id)->where('is_ca_certificate', true)->first();+ $caCertificate = $this->sslCertificates()->where('is_ca_certificate', true)->first();ray('CA certificate generated', $caCertificate);if ($caCertificate) {$certificateContent = $caCertificate->ssl_certificate;diff --git a/database/seeders/CaSslCertSeeder.php b/database/seeders/CaSslCertSeeder.phpindex 09f6cc9840..1b71a5e432 100644--- a/database/seeders/CaSslCertSeeder.php+++ b/database/seeders/CaSslCertSeeder.php@@ -4,7 +4,6 @@ namespace Database\Seeders;use App\Helpers\SslHelper;use App\Models\Server;-use App\Models\SslCertificate;use Illuminate\Database\Seeder;class CaSslCertSeeder extends Seeder@@ -13,7 +12,7 @@ class CaSslCertSeeder extends Seeder{Server::chunk(200, function ($servers) {foreach ($servers as $server) {- $existingCaCert = SslCertificate::where('server_id', $server->id)->where('is_ca_certificate', true)->first();+ $existingCaCert = $server->sslCertificates()->where('is_ca_certificate', true)->first();if (! $existingCaCert) {$caCert = SslHelper::generateSslCertificate(