From dc8da80809a542e7b834c46682dde7b0c19fdaf1 Mon Sep 17 00:00:00 2001 From: Citrons <909229731@qq.com> Date: Mon, 17 Aug 2026 17:31:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(GOV-011):=20=E6=94=AF=E6=8C=81=20MySQL=205.?= =?UTF-8?q?7=20=E7=B3=BB=E5=88=97=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../libs/infrastructure/src/health-clients.test.ts | 13 ++++++++----- .../libs/infrastructure/src/mysql-health.client.ts | 9 +++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/server/libs/infrastructure/src/health-clients.test.ts b/server/libs/infrastructure/src/health-clients.test.ts index 968d62e..bb2e1d0 100644 --- a/server/libs/infrastructure/src/health-clients.test.ts +++ b/server/libs/infrastructure/src/health-clients.test.ts @@ -23,7 +23,7 @@ describe('基础设施只读健康客户端', () => { expect(commands).toEqual(['CONNECT', 'PING']); }); - it('MySQL 使用固定元数据查询并校验 5.7 与数据库口径', async () => { + it('MySQL 使用固定元数据查询并返回实际 5.7.x 版本', async () => { const queries: string[] = []; const client = new MysqlHealthClient( { @@ -32,7 +32,7 @@ describe('基础设施只读健康客户端', () => { return [ [ { - version: '5.7.42-log', + version: '5.7.41-log', databaseName: 'a_share_analysis_dev', charset: 'utf8mb4', collation: 'utf8mb4_general_ci', @@ -49,7 +49,7 @@ describe('基础设施只读健康客户端', () => { await expect(client.check()).resolves.toEqual({ status: 'healthy', - detail: 'MySQL 5.7.42 / a_share_analysis_dev / +08:00', + detail: 'MySQL 5.7.41 / a_share_analysis_dev / +08:00', }); expect(queries).toEqual([MYSQL_HEALTH_QUERY]); }); @@ -76,14 +76,17 @@ describe('基础设施只读健康客户端', () => { 'a_share_analysis_dev', ); - await expect(createClient({ version: '8.0.40' }).check()).rejects.toThrow(/MySQL 5.7/); - await expect(createClient({ version: '5.7.41' }).check()).rejects.toThrow(/5\.7\.42/); + for (const version of ['5.6.51', '8.0.40', '5.7', '5.7.x']) { + await expect(createClient({ version }).check()).rejects.toThrow(/MySQL 5\.7\.x/); + } await expect(createClient({ databaseName: 'a_share_analysis' }).check()).rejects.toThrow( /a_share_analysis_dev/, ); + await expect(createClient({ charset: 'utf8' }).check()).rejects.toThrow(/utf8mb4/); await expect(createClient({ collation: 'utf8mb4_0900_ai_ci' }).check()).rejects.toThrow( /utf8mb4_general_ci/, ); + await expect(createClient({ timezone: 'SYSTEM' }).check()).rejects.toThrow(/\+08:00/); }); it('MySQL 按当前配置校验生产库名', async () => { diff --git a/server/libs/infrastructure/src/mysql-health.client.ts b/server/libs/infrastructure/src/mysql-health.client.ts index f1dd525..388db40 100644 --- a/server/libs/infrastructure/src/mysql-health.client.ts +++ b/server/libs/infrastructure/src/mysql-health.client.ts @@ -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,