refactor(database): enhance application conversion logic and add existence checks for databases and applications
This commit is contained in:
parent
0a1a403940
commit
ed0961e0dc
2 changed files with 27 additions and 22 deletions
|
|
@ -114,8 +114,6 @@ public function convertToApplication()
|
||||||
$serviceDatabase->delete();
|
$serviceDatabase->delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->dispatch('success', 'Database converted to Application. Hasta la vista, database!');
|
|
||||||
|
|
||||||
return redirect()->route('project.service.configuration', $redirectParams);
|
return redirect()->route('project.service.configuration', $redirectParams);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
|
|
|
||||||
|
|
@ -79,24 +79,31 @@ public function convertToDatabase()
|
||||||
try {
|
try {
|
||||||
$service = $this->application->service;
|
$service = $this->application->service;
|
||||||
$serviceApplication = $this->application;
|
$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);
|
// 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) {
|
} catch (\Throwable $e) {
|
||||||
DB::rollBack();
|
|
||||||
|
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue