fix: 补齐消息模板迁移幂等性

This commit is contained in:
sunlei 2026-07-27 17:09:22 +08:00
parent 33e8f28354
commit 8dccecb350
2 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,8 @@
-- QQBot 系统消息推送生产增量迁移。 -- QQBot 系统消息推送生产增量迁移。
-- 仅创建本功能六表、默认模板、菜单和角色授权,不执行历史 QQBot 迁移。 -- 仅创建本功能六表、默认模板、菜单和角色授权,不执行历史 QQBot 迁移。
SET NAMES utf8mb4;
CREATE TABLE IF NOT EXISTS qqbot_message_subscription ( CREATE TABLE IF NOT EXISTS qqbot_message_subscription (
id BIGINT NOT NULL PRIMARY KEY, id BIGINT NOT NULL PRIMARY KEY,
name VARCHAR(100) NOT NULL, 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) KEY idx_qqbot_message_delivery_history (subscription_id, message_event_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) 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 SELECT
2041700000000200601, 2041700000000200601,
'STUN 映射端口变更默认模板', 'STUN 映射端口变更默认模板',
@ -123,7 +125,7 @@ WHERE NOT EXISTS (
AND is_deleted = 0 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 SELECT
2041700000000200602, 2041700000000200602,
'TCP NATMap 端点变更默认模板', 'TCP NATMap 端点变更默认模板',

View File

@ -489,7 +489,13 @@ describe('QQBot message-push SQL contract', () => {
and name = 'STUN 映射端口变更默认模板' and is_deleted = 0 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', () => { 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 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).toContain(expectedTcpTemplate);
expect(sql.match(/2041700000000200602/g)).toHaveLength(1); expect(sql.match(/2041700000000200602/g)).toHaveLength(1);
expect(sql).toContain( expect(sql).toContain(
"'network.stun.mapping-port-changed', '当前STUN的端口已变更为${{endpoint}}'", "'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', () => { it('keeps the TCP template source key aligned with source version 1', () => {