feat: implement MySQL driver and API schema services for database management

This commit is contained in:
Ümit Tunç
2026-04-24 08:29:43 +03:00
parent c433630e33
commit 60cd2fe051
10 changed files with 668 additions and 154 deletions
@@ -104,4 +104,54 @@ class SchemaController extends Controller
return Response::json(['error' => $e->getMessage()], 400);
}
}
public function export(Request $request)
{
try {
$this->initializeDriver($request);
$config = $request->only(['host', 'username', 'password', 'database', 'port']);
$filePath = $this->databaseService->export($config);
return Response::download($filePath)->deleteFileAfterSend(true);
} catch (\Exception $e) {
return Response::json(['error' => $e->getMessage()], 400);
}
}
public function import(Request $request)
{
try {
if (!$request->hasFile('file')) {
return Response::json(['error' => 'No file uploaded'], 400);
}
$this->initializeDriver($request);
$config = $request->only(['host', 'username', 'password', 'database', 'port']);
$file = $request->file('file');
$tempPath = $file->storeAs('temp', $file->getClientOriginalName());
$fullPath = storage_path('app/' . $tempPath);
$this->databaseService->import($config, $fullPath);
if (file_exists($fullPath)) {
unlink($fullPath);
}
return Response::json(['message' => 'Database imported successfully']);
} catch (\Exception $e) {
return Response::json(['error' => $e->getMessage()], 400);
}
}
public function metadata(Request $request, $database)
{
try {
$request->merge(['database' => $database]);
$this->initializeDriver($request);
return Response::json($this->databaseService->getDatabaseMetadata($database));
} catch (\Exception $e) {
return Response::json(['error' => $e->getMessage()], 400);
}
}
}