refactor(database): enhance application conversion logic and add existence checks for databases and applications
This commit is contained in:
@@ -114,8 +114,6 @@ 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);
|
||||
|
||||
@@ -79,7 +79,16 @@ class ServiceApplicationView extends Component
|
||||
try {
|
||||
$service = $this->application->service;
|
||||
$serviceApplication = $this->application;
|
||||
DB::beginTransaction();
|
||||
|
||||
// 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,
|
||||
@@ -91,12 +100,10 @@ class ServiceApplicationView extends Component
|
||||
'is_migrated' => true,
|
||||
]);
|
||||
$serviceApplication->delete();
|
||||
DB::commit();
|
||||
});
|
||||
|
||||
return redirect()->route('project.service.configuration', $this->parameters);
|
||||
return redirect()->route('project.service.configuration', $redirectParams);
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user