feat: implement MySQL driver for database management and add TransferContent UI component
This commit is contained in:
@@ -96,9 +96,14 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
|
|||||||
|
|
||||||
public function export(array $config): string
|
public function export(array $config): string
|
||||||
{
|
{
|
||||||
$filename = 'backup-' . ($config['database'] ?? 'all') . '-' . date('Y-m-d-H-i-s') . '.sql';
|
$database = $config['database'] ?? '';
|
||||||
$directory = storage_path('app/backups');
|
$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)) {
|
if (!is_dir($directory)) {
|
||||||
mkdir($directory, 0755, true);
|
mkdir($directory, 0755, true);
|
||||||
}
|
}
|
||||||
@@ -108,13 +113,10 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
|
|||||||
|
|
||||||
$mysqldumpPath = env('MYSQLDUMP_PATH', 'mysqldump');
|
$mysqldumpPath = env('MYSQLDUMP_PATH', 'mysqldump');
|
||||||
|
|
||||||
// Ensure we have a username
|
|
||||||
$username = $config['username'] ?? 'root';
|
$username = $config['username'] ?? 'root';
|
||||||
$password = $config['password'] ?? '';
|
$password = $config['password'] ?? '';
|
||||||
$host = $config['host'] ?? '127.0.0.1';
|
$host = $config['host'] ?? '127.0.0.1';
|
||||||
$port = $config['port'] ?? '3306';
|
$port = $config['port'] ?? '3306';
|
||||||
$database = $config['database'] ?? '';
|
|
||||||
$table = $config['table'] ?? '';
|
|
||||||
|
|
||||||
// Build command with flags for a complete and resilient export
|
// Build command with flags for a complete and resilient export
|
||||||
$passwordPart = !empty($password) ? "-p" . escapeshellarg($password) : "";
|
$passwordPart = !empty($password) ? "-p" . escapeshellarg($password) : "";
|
||||||
@@ -236,16 +238,16 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
|
|||||||
{
|
{
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
ENGINE as engine,
|
ENGINE as `engine`,
|
||||||
TABLE_ROWS as rows,
|
TABLE_ROWS as `rows`,
|
||||||
DATA_LENGTH as data_length,
|
DATA_LENGTH as `data_length`,
|
||||||
INDEX_LENGTH as index_length,
|
INDEX_LENGTH as `index_length`,
|
||||||
DATA_FREE as data_free,
|
DATA_FREE as `data_free`,
|
||||||
AUTO_INCREMENT as auto_increment,
|
AUTO_INCREMENT as `auto_increment`,
|
||||||
CREATE_TIME as create_time,
|
CREATE_TIME as `create_time`,
|
||||||
UPDATE_TIME as update_time,
|
UPDATE_TIME as `update_time`,
|
||||||
TABLE_COLLATION as collation,
|
TABLE_COLLATION as `collation`,
|
||||||
TABLE_COMMENT as comment
|
TABLE_COMMENT as `comment`
|
||||||
FROM
|
FROM
|
||||||
information_schema.TABLES
|
information_schema.TABLES
|
||||||
WHERE
|
WHERE
|
||||||
|
|||||||
@@ -41,8 +41,9 @@ const TransferContent: React.FC<TransferContentProps> = ({ mode = 'both' }) => {
|
|||||||
const url = window.URL.createObjectURL(new Blob([response.data]));
|
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
const contextName = activeTable ? `${activeDatabase}-${activeTable}` : (activeDatabase || 'all');
|
const filename = activeTable
|
||||||
const filename = `backup-${contextName}-${new Date().toISOString().split('T')[0]}.sql`;
|
? `${activeTable}-${new Date().toISOString().split('T')[0]}.sql`
|
||||||
|
: `backup-${activeDatabase || 'all'}-${new Date().toISOString().split('T')[0]}.sql`;
|
||||||
link.setAttribute('download', filename);
|
link.setAttribute('download', filename);
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
|
|||||||
Reference in New Issue
Block a user