mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 10:32:48 +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;
|
||||
@@ -14,6 +14,8 @@ class ToolsDbInfoBase extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this->setName('tools:db:info')
|
||||
->setDescription('显示数据库连接信息和表列表')
|
||||
->addOption('with-count', null, Option::VALUE_NONE, '显示每个表的记录数')
|
||||
@@ -24,12 +26,12 @@ class ToolsDbInfoBase extends Command
|
||||
protected function execute($input, $output)
|
||||
{
|
||||
if ($input->getOption('help')) {
|
||||
$service = new ToolsDbServiceBase();
|
||||
$service = new DbService();
|
||||
$service->showHelp('tools:db:info', $output);
|
||||
return;
|
||||
}
|
||||
|
||||
$service = new ToolsDbServiceBase();
|
||||
$service = new DbService();
|
||||
|
||||
if (!$service->checkDebugMode($output)) {
|
||||
return;
|
||||
@@ -47,11 +49,69 @@ class ToolsDbInfoBase extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln('');
|
||||
$output->writeln('<comment>' . str_repeat('=', 60) . '</comment>');
|
||||
$output->writeln('<info>数据库连接信息</info>');
|
||||
$output->writeln('<comment>' . str_repeat('=', 60) . '</comment>');
|
||||
$output->writeln('');
|
||||
$tables = Db::connect($connection)->getTables();
|
||||
|
||||
$tableList = [];
|
||||
if (!empty($tables)) {
|
||||
$prefix = $config['prefix'] ?? '';
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$shortName = $table;
|
||||
if ($prefix && str_starts_with($table, $prefix)) {
|
||||
$shortName = substr($table, strlen($prefix));
|
||||
}
|
||||
|
||||
$tableItem = [
|
||||
'name' => $shortName,
|
||||
'full_name' => $table
|
||||
];
|
||||
|
||||
if ($withCount) {
|
||||
$count = Db::connect($connection)->table($table)->count();
|
||||
$tableItem['count'] = $count;
|
||||
}
|
||||
|
||||
$tableList[] = $tableItem;
|
||||
}
|
||||
}
|
||||
|
||||
$output->newLine();
|
||||
$output->comment(str_repeat('=', 60));
|
||||
$output->info('数据库连接信息');
|
||||
$output->comment(str_repeat('=', 60));
|
||||
$output->newLine();
|
||||
|
||||
$output->info('连接名称:' . $connection);
|
||||
$output->info('数据库类型:' . ($config['type'] ?? 'unknown'));
|
||||
$output->info('主机地址:' . ($config['hostname'] ?? 'unknown'));
|
||||
$output->info('数据库名:' . ($config['database'] ?? 'unknown'));
|
||||
$output->info('端口:' . ($config['hostport'] ?? 'unknown'));
|
||||
$output->info('字符集:' . ($config['charset'] ?? 'unknown'));
|
||||
$output->info('表前缀:' . ($config['prefix'] ?? ''));
|
||||
$output->newLine();
|
||||
|
||||
$output->comment(str_repeat('-', 60));
|
||||
$output->info('表列表');
|
||||
$output->comment(str_repeat('-', 60));
|
||||
$output->newLine();
|
||||
|
||||
if (empty($tables)) {
|
||||
$output->writeln('无表');
|
||||
$output->newLine();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($tableList as $tableItem) {
|
||||
if ($withCount) {
|
||||
$output->info(str_pad($tableItem['name'], 40) . ($tableItem['count'] ?? 0) . ' 条记录');
|
||||
} else {
|
||||
$output->info($tableItem['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$output->newLine();
|
||||
$output->comment(str_repeat('=', 60));
|
||||
$output->newLine();
|
||||
$output->writeln('<info>连接名称:</info>' . $connection);
|
||||
$output->writeln('<info>数据库类型:</info>' . ($config['type'] ?? 'unknown'));
|
||||
$output->writeln('<info>主机地址:</info>' . ($config['hostname'] ?? 'unknown'));
|
||||
@@ -66,27 +126,17 @@ class ToolsDbInfoBase extends Command
|
||||
$output->writeln('<comment>' . str_repeat('-', 60) . '</comment>');
|
||||
$output->writeln('');
|
||||
|
||||
$tables = Db::connect($connection)->getTables();
|
||||
|
||||
if (empty($tables)) {
|
||||
$output->writeln('无表');
|
||||
$output->writeln('');
|
||||
return;
|
||||
}
|
||||
|
||||
$prefix = $config['prefix'] ?? '';
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$shortName = $table;
|
||||
if ($prefix && str_starts_with($table, $prefix)) {
|
||||
$shortName = substr($table, strlen($prefix));
|
||||
}
|
||||
|
||||
foreach ($tableList as $tableItem) {
|
||||
if ($withCount) {
|
||||
$count = Db::connect($connection)->table($table)->count();
|
||||
$output->writeln('<info>' . str_pad($shortName, 40) . '</info>' . $count . ' 条记录');
|
||||
$output->writeln('<info>' . str_pad($tableItem['name'], 40) . '</info>' . ($tableItem['count'] ?? 0) . ' 条记录');
|
||||
} else {
|
||||
$output->writeln('<info>' . $shortName . '</info>');
|
||||
$output->writeln('<info>' . $tableItem['name'] . '</info>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,4 +148,4 @@ class ToolsDbInfoBase extends Command
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user