fix(GOV-011): 支持 MySQL 5.7 系列健康检查

This commit is contained in:
2026-08-17 17:31:10 +08:00
parent 54499f0678
commit dc8da80809
2 changed files with 13 additions and 9 deletions
@@ -36,8 +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 (!/^5\.7\.42(?:[-+.]|$)/.test(row.version)) {
throw new Error('MySQL 5.7.42 版本要求未满足');
const versionMatch = /^(5\.7\.\d+)(?:[-+].*)?$/.exec(row.version ?? '');
if (!versionMatch) {
throw new Error('MySQL 5.7.x 版本要求未满足');
}
if (row.databaseName !== this.expectedDatabase) {
throw new Error(`MySQL 健康检查必须连接 ${this.expectedDatabase}`);
@@ -50,7 +51,7 @@ export class MysqlHealthClient implements OnModuleDestroy {
return {
status: 'healthy',
detail: `MySQL 5.7.42 / ${row.databaseName} / ${row.timezone}`,
detail: `MySQL ${versionMatch[1]} / ${row.databaseName} / ${row.timezone}`,
};
}
@@ -63,7 +64,7 @@ export class MysqlHealthClient implements OnModuleDestroy {
}
}
/** 创建最多两个连接的只读健康池,并显式应用 MySQL 5.7.42 会话时区。 */
/** 创建最多两个连接的只读健康池,并显式应用 MySQL 5.7.x 会话时区。 */
export function createMysqlHealthClient(config: MysqlRuntimeConfig): MysqlHealthClient {
const pool: Pool = createPool({
host: config.host,