From b00a8448e1e937a3bce5dc5d2a7306197f51c455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Fri, 24 Apr 2026 12:53:21 +0300 Subject: [PATCH] feat: implement MySQL driver for database management and add TransferContent UI component --- backend/app/Services/Database/MySqlDriver.php | 32 ++++++++++--------- frontend/src/components/TransferContent.tsx | 5 +-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/app/Services/Database/MySqlDriver.php b/backend/app/Services/Database/MySqlDriver.php index 797ce15..d30f87c 100644 --- a/backend/app/Services/Database/MySqlDriver.php +++ b/backend/app/Services/Database/MySqlDriver.php @@ -96,9 +96,14 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface public function export(array $config): string { - $filename = 'backup-' . ($config['database'] ?? 'all') . '-' . date('Y-m-d-H-i-s') . '.sql'; - $directory = storage_path('app/backups'); + $database = $config['database'] ?? ''; + $table = $config['table'] ?? ''; + $filename = !empty($table) + ? "{$table}-" . date('Y-m-d') . ".sql" + : "backup-" . ($database ?: 'all') . "-" . date('Y-m-d') . ".sql"; + + $directory = storage_path('app/backups'); if (!is_dir($directory)) { mkdir($directory, 0755, true); } @@ -108,13 +113,10 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface $mysqldumpPath = env('MYSQLDUMP_PATH', 'mysqldump'); - // Ensure we have a username $username = $config['username'] ?? 'root'; $password = $config['password'] ?? ''; $host = $config['host'] ?? '127.0.0.1'; $port = $config['port'] ?? '3306'; - $database = $config['database'] ?? ''; - $table = $config['table'] ?? ''; // Build command with flags for a complete and resilient export $passwordPart = !empty($password) ? "-p" . escapeshellarg($password) : ""; @@ -236,16 +238,16 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface { $sql = " SELECT - ENGINE as engine, - TABLE_ROWS as rows, - DATA_LENGTH as data_length, - INDEX_LENGTH as index_length, - DATA_FREE as data_free, - AUTO_INCREMENT as auto_increment, - CREATE_TIME as create_time, - UPDATE_TIME as update_time, - TABLE_COLLATION as collation, - TABLE_COMMENT as comment + ENGINE as `engine`, + TABLE_ROWS as `rows`, + DATA_LENGTH as `data_length`, + INDEX_LENGTH as `index_length`, + DATA_FREE as `data_free`, + AUTO_INCREMENT as `auto_increment`, + CREATE_TIME as `create_time`, + UPDATE_TIME as `update_time`, + TABLE_COLLATION as `collation`, + TABLE_COMMENT as `comment` FROM information_schema.TABLES WHERE diff --git a/frontend/src/components/TransferContent.tsx b/frontend/src/components/TransferContent.tsx index 35eb7de..71b42a7 100644 --- a/frontend/src/components/TransferContent.tsx +++ b/frontend/src/components/TransferContent.tsx @@ -41,8 +41,9 @@ const TransferContent: React.FC = ({ mode = 'both' }) => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; - const contextName = activeTable ? `${activeDatabase}-${activeTable}` : (activeDatabase || 'all'); - const filename = `backup-${contextName}-${new Date().toISOString().split('T')[0]}.sql`; + const filename = activeTable + ? `${activeTable}-${new Date().toISOString().split('T')[0]}.sql` + : `backup-${activeDatabase || 'all'}-${new Date().toISOString().split('T')[0]}.sql`; link.setAttribute('download', filename); document.body.appendChild(link); link.click();