feat(tools/db): 在表结构描述中显示表注释

This commit is contained in:
augushong
2026-02-01 00:22:51 +08:00
parent 6aa176a39a
commit b6b690edb3

View File

@@ -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)) {