From 8dccecb3500b809030fbda31406d033c0da5b173 Mon Sep 17 00:00:00 2001 From: sunlei Date: Mon, 27 Jul 2026 17:09:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A5=E9=BD=90=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E8=BF=81=E7=A7=BB=E5=B9=82=E7=AD=89=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/qqbot-message-push-init.sql | 6 ++++-- .../qqbot-message-push-sql.spec.ts | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sql/qqbot-message-push-init.sql b/sql/qqbot-message-push-init.sql index d97fb3a..d2a4409 100644 --- a/sql/qqbot-message-push-init.sql +++ b/sql/qqbot-message-push-init.sql @@ -1,6 +1,8 @@ -- QQBot 系统消息推送生产增量迁移。 -- 仅创建本功能六表、默认模板、菜单和角色授权,不执行历史 QQBot 迁移。 +SET NAMES utf8mb4; + CREATE TABLE IF NOT EXISTS qqbot_message_subscription ( id BIGINT NOT NULL PRIMARY KEY, name VARCHAR(100) NOT NULL, @@ -106,7 +108,7 @@ CREATE TABLE IF NOT EXISTS qqbot_message_delivery ( KEY idx_qqbot_message_delivery_history (subscription_id, message_event_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -INSERT INTO qqbot_message_template (id, name, source_key, content, enabled, remark, is_deleted) +INSERT IGNORE INTO qqbot_message_template (id, name, source_key, content, enabled, remark, is_deleted) SELECT 2041700000000200601, 'STUN 映射端口变更默认模板', @@ -123,7 +125,7 @@ WHERE NOT EXISTS ( AND is_deleted = 0 ); -INSERT INTO qqbot_message_template (id, name, source_key, content, enabled, remark, is_deleted) +INSERT IGNORE INTO qqbot_message_template (id, name, source_key, content, enabled, remark, is_deleted) SELECT 2041700000000200602, 'TCP NATMap 端点变更默认模板', diff --git a/test/modules/qqbot/message-push/qqbot-message-push-sql.spec.ts b/test/modules/qqbot/message-push/qqbot-message-push-sql.spec.ts index f878ba7..011af5c 100644 --- a/test/modules/qqbot/message-push/qqbot-message-push-sql.spec.ts +++ b/test/modules/qqbot/message-push/qqbot-message-push-sql.spec.ts @@ -489,7 +489,13 @@ describe('QQBot message-push SQL contract', () => { and name = 'STUN 映射端口变更默认模板' and is_deleted = 0 ); `); - for (const sql of [bootstrapSql, seedSql, migrationSql]) expect(sql).toContain(expectedTemplate); + for (const sql of [bootstrapSql, seedSql]) expect(sql).toContain(expectedTemplate); + expect(migrationSql).toContain( + expectedTemplate.replace( + 'insert into qqbot_message_template', + 'insert ignore into qqbot_message_template', + ), + ); }); it('adds the exact TCP NATMap template without changing the STUN template', () => { @@ -503,13 +509,23 @@ describe('QQBot message-push SQL contract', () => { and name = 'TCP NATMap 端点变更默认模板' and is_deleted = 0 ); `); - for (const sql of [bootstrapSql, seedSql, migrationSql]) { + for (const sql of [bootstrapSql, seedSql]) { expect(sql).toContain(expectedTcpTemplate); expect(sql.match(/2041700000000200602/g)).toHaveLength(1); expect(sql).toContain( "'network.stun.mapping-port-changed', '当前STUN的端口已变更为${{endpoint}}'", ); } + expect(migrationSql).toContain( + expectedTcpTemplate.replace( + 'insert into qqbot_message_template', + 'insert ignore into qqbot_message_template', + ), + ); + expect(migrationSql.match(/2041700000000200602/g)).toHaveLength(1); + expect(migrationSql).toContain( + "'network.stun.mapping-port-changed', '当前STUN的端口已变更为${{endpoint}}'", + ); }); it('keeps the TCP template source key aligned with source version 1', () => {