fix(GOV-009): 完成脚手架审查整改

This commit is contained in:
2026-08-13 18:30:57 +08:00
parent dcdf634457
commit 3a8120a33a
47 changed files with 752 additions and 101 deletions
@@ -4,6 +4,7 @@ import type { OnModuleDestroy } from '@nestjs/common';
import type { MysqlRuntimeConfig } from '../../config/src/runtime-config';
import type { DependencyHealthDto } from '../../http-contracts/src/health.dto';
/** 固定的只读元数据查询,用于验证服务端版本、库名和会话字符口径。 */
export const MYSQL_HEALTH_QUERY = `SELECT
VERSION() AS version,
DATABASE() AS databaseName,
@@ -24,6 +25,7 @@ interface MysqlMetadataRow {
timezone: string;
}
/** MySQL 健康客户端只校验元数据,不读取表数据或执行写入。 */
export class MysqlHealthClient implements OnModuleDestroy {
constructor(
private readonly client: MysqlQueryPort,
@@ -34,7 +36,9 @@ export class MysqlHealthClient implements OnModuleDestroy {
const [rows] = await this.client.query(MYSQL_HEALTH_QUERY);
const row = (rows as unknown as MysqlMetadataRow[])[0];
if (!row) throw new Error('MySQL 未返回元数据');
if (!row.version.startsWith('5.7.')) throw new Error('MySQL 5.7.x 版本要求未满足');
if (!/^5\.7\.42(?:[-+.]|$)/.test(row.version)) {
throw new Error('MySQL 5.7.42 版本要求未满足');
}
if (row.databaseName !== this.expectedDatabase) {
throw new Error(`MySQL 健康检查必须连接 ${this.expectedDatabase}`);
}
@@ -46,7 +50,7 @@ export class MysqlHealthClient implements OnModuleDestroy {
return {
status: 'healthy',
detail: `MySQL 5.7 / ${row.databaseName} / ${row.timezone}`,
detail: `MySQL 5.7.42 / ${row.databaseName} / ${row.timezone}`,
};
}
@@ -59,6 +63,7 @@ export class MysqlHealthClient implements OnModuleDestroy {
}
}
/** 创建最多两个连接的只读健康池,并显式应用 MySQL 5.7.42 会话时区。 */
export function createMysqlHealthClient(config: MysqlRuntimeConfig): MysqlHealthClient {
const pool: Pool = createPool({
host: config.host,