mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 10:02:49 +08:00
feat: 发布智能体版
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace base\common\command\tools\db;
|
||||
|
||||
use base\common\service\ToolsDbServiceBase;
|
||||
use think\console\Command;
|
||||
use app\common\service\tools\DbService;
|
||||
use app\common\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
@@ -13,6 +13,8 @@ class ToolsDbDescBase extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this->setName('tools:db:desc')
|
||||
->setDescription('显示表结构信息')
|
||||
->addArgument('table', null, '表名')
|
||||
@@ -24,12 +26,12 @@ class ToolsDbDescBase extends Command
|
||||
protected function execute($input, $output)
|
||||
{
|
||||
if ($input->getOption('help')) {
|
||||
$service = new ToolsDbServiceBase();
|
||||
$service = new DbService();
|
||||
$service->showHelp('tools:db:desc', $output);
|
||||
return;
|
||||
}
|
||||
|
||||
$service = new ToolsDbServiceBase();
|
||||
$service = new DbService();
|
||||
|
||||
if (!$service->checkDebugMode($output)) {
|
||||
return;
|
||||
@@ -48,12 +50,6 @@ class ToolsDbDescBase extends Command
|
||||
$showIndex = $input->getOption('show-index');
|
||||
|
||||
try {
|
||||
$output->writeln('');
|
||||
$output->writeln('<comment>' . str_repeat('=', 60) . '</comment>');
|
||||
$output->writeln('<info>表结构:' . $fullTableName . '</info>');
|
||||
$output->writeln('<comment>' . str_repeat('=', 60) . '</comment>');
|
||||
$output->writeln('');
|
||||
|
||||
$tableComment = '';
|
||||
try {
|
||||
$escaped = addcslashes($fullTableName, "\\_%");
|
||||
@@ -77,9 +73,6 @@ class ToolsDbDescBase extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln('<info>表注释:</info>' . $tableComment);
|
||||
$output->writeln('');
|
||||
|
||||
$columns = Db::connect($connection)->query("SHOW FULL COLUMNS FROM `$fullTableName`");
|
||||
|
||||
if (empty($columns)) {
|
||||
@@ -88,6 +81,45 @@ class ToolsDbDescBase extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$columnData = [];
|
||||
foreach ($columns as $column) {
|
||||
$columnData[] = [
|
||||
'name' => $column['Field'],
|
||||
'type' => $column['Type'],
|
||||
'null' => $column['Null'] === 'YES',
|
||||
'key' => $column['Key'],
|
||||
'default' => $column['Default'] ?? null,
|
||||
'extra' => $column['Extra'] ?? '',
|
||||
'comment' => $column['Comment'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
$indexData = [];
|
||||
if ($showIndex) {
|
||||
$indexes = Db::connect($connection)->query("SHOW INDEX FROM `$fullTableName`");
|
||||
|
||||
if (!empty($indexes)) {
|
||||
foreach ($indexes as $index) {
|
||||
$indexData[] = [
|
||||
'name' => $index['Key_name'],
|
||||
'column' => $index['Column_name'],
|
||||
'unique' => $index['Non_unique'] == 0,
|
||||
'type' => $index['Index_type'],
|
||||
'sequence' => $index['Seq_in_index'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output->newLine();
|
||||
$output->comment(str_repeat('=', 60));
|
||||
$output->info('表结构:' . $fullTableName);
|
||||
$output->comment(str_repeat('=', 60));
|
||||
$output->newLine();
|
||||
|
||||
$output->info('表注释:' . $tableComment);
|
||||
$output->newLine();
|
||||
|
||||
$tableData = [];
|
||||
foreach ($columns as $column) {
|
||||
$tableData[] = [
|
||||
@@ -104,18 +136,16 @@ class ToolsDbDescBase extends Command
|
||||
$service->formatTableOutput($tableData, $output);
|
||||
|
||||
if ($showIndex) {
|
||||
$output->writeln('');
|
||||
$output->writeln('<comment>' . str_repeat('-', 60) . '</comment>');
|
||||
$output->writeln('<info>索引信息</info>');
|
||||
$output->writeln('<comment>' . str_repeat('-', 60) . '</comment>');
|
||||
$output->writeln('');
|
||||
|
||||
$indexes = Db::connect($connection)->query("SHOW INDEX FROM `$fullTableName`");
|
||||
$output->newLine();
|
||||
$output->comment(str_repeat('-', 60));
|
||||
$output->info('索引信息');
|
||||
$output->comment(str_repeat('-', 60));
|
||||
$output->newLine();
|
||||
|
||||
if (!empty($indexes)) {
|
||||
$indexData = [];
|
||||
$indexDataDisplay = [];
|
||||
foreach ($indexes as $index) {
|
||||
$indexData[] = [
|
||||
$indexDataDisplay[] = [
|
||||
'索引名' => $index['Key_name'],
|
||||
'列名' => $index['Column_name'],
|
||||
'唯一' => $index['Non_unique'] == 0 ? '是' : '否',
|
||||
@@ -123,18 +153,18 @@ class ToolsDbDescBase extends Command
|
||||
'顺序' => $index['Seq_in_index'],
|
||||
];
|
||||
}
|
||||
$service->formatTableOutput($indexData, $output);
|
||||
$service->formatTableOutput($indexDataDisplay, $output);
|
||||
} else {
|
||||
$output->writeln('无索引');
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln('');
|
||||
$output->writeln('<comment>' . str_repeat('=', 60) . '</comment>');
|
||||
$output->writeln('');
|
||||
$output->newLine();
|
||||
$output->comment(str_repeat('=', 60));
|
||||
$output->newLine();
|
||||
} catch (\Exception $e) {
|
||||
$output->error('获取表结构失败:' . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user