mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 02:22:48 +08:00
feat(tools/db): 在表结构描述中显示表注释
This commit is contained in:
@@ -54,6 +54,32 @@ class ToolsDbDescBase extends Command
|
||||
$output->writeln('<comment>' . str_repeat('=', 60) . '</comment>');
|
||||
$output->writeln('');
|
||||
|
||||
$tableComment = '';
|
||||
try {
|
||||
$escaped = addcslashes($fullTableName, "\\_%");
|
||||
$rows = Db::connect($connection)->query("SHOW TABLE STATUS LIKE '$escaped'");
|
||||
if (!empty($rows)) {
|
||||
$tableComment = (string)($rows[0]['Comment'] ?? '');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
|
||||
if ($tableComment === '') {
|
||||
try {
|
||||
$rows = Db::connect($connection)->query("SHOW CREATE TABLE `$fullTableName`");
|
||||
if (!empty($rows)) {
|
||||
$create = $rows[0]['Create Table'] ?? '';
|
||||
if ($create !== '' && preg_match("/COMMENT='(.*?)'/s", $create, $matches)) {
|
||||
$tableComment = stripcslashes($matches[1]);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln('<info>表注释:</info>' . $tableComment);
|
||||
$output->writeln('');
|
||||
|
||||
$columns = Db::connect($connection)->query("SHOW FULL COLUMNS FROM `$fullTableName`");
|
||||
|
||||
if (empty($columns)) {
|
||||
|
||||
Reference in New Issue
Block a user