Update app/Livewire/Project/Service/Database.php

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Andras Bacsai
2025-04-30 18:26:43 +02:00
committed by GitHub
parent 114fafb270
commit 0a1a403940

View File

@@ -89,7 +89,18 @@ class Database extends Component
try { try {
$service = $this->database->service; $service = $this->database->service;
$serviceDatabase = $this->database; $serviceDatabase = $this->database;
DB::beginTransaction();
// Check if application with same name already exists
if ($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([ $service->applications()->create([
'name' => $serviceDatabase->name, 'name' => $serviceDatabase->name,
'human_name' => $serviceDatabase->human_name, 'human_name' => $serviceDatabase->human_name,
@@ -101,12 +112,12 @@ class Database extends Component
'is_migrated' => true, 'is_migrated' => true,
]); ]);
$serviceDatabase->delete(); $serviceDatabase->delete();
DB::commit(); });
return redirect()->route('project.service.configuration', $this->parameters); $this->dispatch('success', 'Database converted to Application. Hasta la vista, database!');
return redirect()->route('project.service.configuration', $redirectParams);
} catch (\Throwable $e) { } catch (\Throwable $e) {
DB::rollBack();
return handleError($e, $this); return handleError($e, $this);
} }
} }