chore: show runtime DB server identity in db_diag

Add config and server-level DB identity fields (host/port/user, @@hostname/@@port/@@version) to packaging-units db_diag so production can verify the exact runtime DB endpoint.
This commit is contained in:
taekyoungc
2026-04-09 12:54:35 +09:00
parent cd2d41b3d7
commit 8e859f420d
2 changed files with 25 additions and 0 deletions

View File

@@ -343,7 +343,13 @@ class Bag extends BaseController
if ($this->request->getGet('db_diag') === '1') { if ($this->request->getGet('db_diag') === '1') {
$dbDiag = [ $dbDiag = [
'lg_idx' => $lgIdx, 'lg_idx' => $lgIdx,
'cfg_host' => null,
'cfg_port' => null,
'cfg_user' => null,
'db_name' => null, 'db_name' => null,
'mysql_host' => null,
'mysql_port' => null,
'mysql_version' => null,
'packaging_unit' => null, 'packaging_unit' => null,
'code_kind' => null, 'code_kind' => null,
'code_detail' => null, 'code_detail' => null,
@@ -351,7 +357,20 @@ class Bag extends BaseController
]; ];
try { try {
$db = db_connect(); $db = db_connect();
$cfg = config('Database')->default ?? [];
$dbDiag['cfg_host'] = $cfg['hostname'] ?? null;
$dbDiag['cfg_port'] = isset($cfg['port']) ? (string) $cfg['port'] : null;
$dbDiag['cfg_user'] = $cfg['username'] ?? null;
$dbDiag['db_name'] = $db->database; $dbDiag['db_name'] = $db->database;
$meta = $db->query('SELECT @@hostname AS mysql_host, @@port AS mysql_port, @@version AS mysql_version, DATABASE() AS db_name')->getRowArray();
if (is_array($meta)) {
$dbDiag['mysql_host'] = $meta['mysql_host'] ?? null;
$dbDiag['mysql_port'] = isset($meta['mysql_port']) ? (string) $meta['mysql_port'] : null;
$dbDiag['mysql_version'] = $meta['mysql_version'] ?? null;
if (! empty($meta['db_name'])) {
$dbDiag['db_name'] = (string) $meta['db_name'];
}
}
$dbDiag['packaging_unit'] = (int) $db->table('packaging_unit')->where('pu_lg_idx', (int) $lgIdx)->countAllResults(); $dbDiag['packaging_unit'] = (int) $db->table('packaging_unit')->where('pu_lg_idx', (int) $lgIdx)->countAllResults();
$dbDiag['code_kind'] = (int) $db->table('code_kind')->countAllResults(); $dbDiag['code_kind'] = (int) $db->table('code_kind')->countAllResults();
$dbDiag['code_detail'] = (int) $db->table('code_detail')->countAllResults(); $dbDiag['code_detail'] = (int) $db->table('code_detail')->countAllResults();

View File

@@ -3,7 +3,13 @@
<section class="rounded border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-900"> <section class="rounded border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-900">
<div class="font-semibold mb-1">DB 진단 모드</div> <div class="font-semibold mb-1">DB 진단 모드</div>
<div>lg_idx: <?= esc((string) ($dbDiag['lg_idx'] ?? 'null')) ?></div> <div>lg_idx: <?= esc((string) ($dbDiag['lg_idx'] ?? 'null')) ?></div>
<div>cfg_host: <?= esc((string) ($dbDiag['cfg_host'] ?? '')) ?></div>
<div>cfg_port: <?= esc((string) ($dbDiag['cfg_port'] ?? '')) ?></div>
<div>cfg_user: <?= esc((string) ($dbDiag['cfg_user'] ?? '')) ?></div>
<div>database: <?= esc((string) ($dbDiag['db_name'] ?? '')) ?></div> <div>database: <?= esc((string) ($dbDiag['db_name'] ?? '')) ?></div>
<div>mysql_host(@@hostname): <?= esc((string) ($dbDiag['mysql_host'] ?? '')) ?></div>
<div>mysql_port(@@port): <?= esc((string) ($dbDiag['mysql_port'] ?? '')) ?></div>
<div>mysql_version(@@version): <?= esc((string) ($dbDiag['mysql_version'] ?? '')) ?></div>
<div>packaging_unit(현재 lg): <?= esc((string) ($dbDiag['packaging_unit'] ?? 'null')) ?></div> <div>packaging_unit(현재 lg): <?= esc((string) ($dbDiag['packaging_unit'] ?? 'null')) ?></div>
<div>code_kind: <?= esc((string) ($dbDiag['code_kind'] ?? 'null')) ?></div> <div>code_kind: <?= esc((string) ($dbDiag['code_kind'] ?? 'null')) ?></div>
<div>code_detail: <?= esc((string) ($dbDiag['code_detail'] ?? 'null')) ?></div> <div>code_detail: <?= esc((string) ($dbDiag['code_detail'] ?? 'null')) ?></div>