feat: implement dynamic database management via MySQL driver and API controllers
This commit is contained in:
@@ -114,10 +114,16 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
|
||||
$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) : "";
|
||||
$dbPart = !empty($database) ? escapeshellarg($database) : "--all-databases";
|
||||
|
||||
if (!empty($table) && !empty($database)) {
|
||||
$dbPart = escapeshellarg($database) . " " . escapeshellarg($table);
|
||||
} else {
|
||||
$dbPart = !empty($database) ? escapeshellarg($database) : "--all-databases";
|
||||
}
|
||||
|
||||
// --single-transaction: for InnoDB tables, ensures consistency without locking
|
||||
// --skip-lock-tables: avoids issues with views/definers that might prevent locking
|
||||
@@ -225,4 +231,35 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
|
||||
$results = $this->query($sql, [$database]);
|
||||
return (array) ($results[0] ?? []);
|
||||
}
|
||||
|
||||
public function getTableMetadata(string $database, string $table): array
|
||||
{
|
||||
$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
|
||||
FROM
|
||||
information_schema.TABLES
|
||||
WHERE
|
||||
TABLE_SCHEMA = ? AND
|
||||
TABLE_NAME = ?
|
||||
";
|
||||
|
||||
$results = $this->query($sql, [$database, $table]);
|
||||
return (array) ($results[0] ?? []);
|
||||
}
|
||||
|
||||
public function truncateTable(string $table): bool
|
||||
{
|
||||
DB::connection($this->connectionName)->statement("TRUNCATE TABLE `{$table}`");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user