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(database): enhance application conversion logic and add existence checks for databases and applications
Andras Bacsaied0961e0dcbd
diff --git a/app/Livewire/Project/Service/Database.php b/app/Livewire/Project/Service/Database.phpindex 07521f5de6..0af757c8ca 100644--- a/app/Livewire/Project/Service/Database.php+++ b/app/Livewire/Project/Service/Database.php@@ -89,17 +89,17 @@ class Database extends Componenttry {$service = $this->database->service;$serviceDatabase = $this->database;-+// Check if application with same name already existsif ($service->applications()->where('name', $serviceDatabase->name)->exists()) {throw new \Exception('An application with this name already exists.');}-+// Create new parameters removing database_uuid$redirectParams = collect($this->parameters)->except('database_uuid')->all();-+DB::transaction(function () use ($service, $serviceDatabase) {$service->applications()->create(['name' => $serviceDatabase->name,@@ -113,9 +113,7 @@ class Database extends Component]);$serviceDatabase->delete();});-- $this->dispatch('success', 'Database converted to Application. Hasta la vista, database!');-+return redirect()->route('project.service.configuration', $redirectParams);} catch (\Throwable $e) {return handleError($e, $this);diff --git a/app/Livewire/Project/Service/ServiceApplicationView.php b/app/Livewire/Project/Service/ServiceApplicationView.phpindex 7dc184ccdd..64f7ab95c5 100644--- a/app/Livewire/Project/Service/ServiceApplicationView.php+++ b/app/Livewire/Project/Service/ServiceApplicationView.php@@ -79,24 +79,31 @@ class ServiceApplicationView extends Componenttry {$service = $this->application->service;$serviceApplication = $this->application;- DB::beginTransaction();- $service->databases()->create([- 'name' => $serviceApplication->name,- 'human_name' => $serviceApplication->human_name,- 'description' => $serviceApplication->description,- 'exclude_from_status' => $serviceApplication->exclude_from_status,- 'is_log_drain_enabled' => $serviceApplication->is_log_drain_enabled,- 'image' => $serviceApplication->image,- 'service_id' => $service->id,- 'is_migrated' => true,- ]);- $serviceApplication->delete();- DB::commit();- return redirect()->route('project.service.configuration', $this->parameters);- } catch (\Throwable $e) {- DB::rollBack();+ // Check if database with same name already exists+ if ($service->databases()->where('name', $serviceApplication->name)->exists()) {+ throw new \Exception('A database with this name already exists.');+ }+ $redirectParams = collect($this->parameters)+ ->except('database_uuid')+ ->all();+ DB::transaction(function () use ($service, $serviceApplication) {+ $service->databases()->create([+ 'name' => $serviceApplication->name,+ 'human_name' => $serviceApplication->human_name,+ 'description' => $serviceApplication->description,+ 'exclude_from_status' => $serviceApplication->exclude_from_status,+ 'is_log_drain_enabled' => $serviceApplication->is_log_drain_enabled,+ 'image' => $serviceApplication->image,+ 'service_id' => $service->id,+ 'is_migrated' => true,+ ]);+ $serviceApplication->delete();+ });++ return redirect()->route('project.service.configuration', $redirectParams);+ } catch (\Throwable $e) {return handleError($e, $this);}}