Files
zyt/server/sql/1.9.20260507/add_tcm_im_chat_message_table.sql
T
2026-05-07 17:36:00 +08:00

29 lines
2.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 诊单腾讯云 IM 单聊消息归档(定时从 admin_getroammsg 同步,突破云端约 7 天漫游限制)
-- 已在生产部分环境创建(参见 server/database/migrations/create_tcm_im_chat_message.sql
-- 此处使用 IF NOT EXISTS 安全重入,确保新环境部署时一并建表
CREATE TABLE IF NOT EXISTS `zyt_tcm_im_chat_message` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`diagnosis_id` int unsigned NOT NULL DEFAULT 0 COMMENT '诊单ID',
`patient_id` int unsigned NOT NULL DEFAULT 0 COMMENT '患者ID(冗余,便于按患者维度排查/统计)',
`msg_id` varchar(160) NOT NULL DEFAULT '' COMMENT '业务唯一键:MsgSeq_MsgRandom_From_Account',
`from_account` varchar(64) NOT NULL DEFAULT '' COMMENT '发送方 IM UserID',
`to_account` varchar(64) NOT NULL DEFAULT '' COMMENT '接收方 IM UserID',
`msg_time` int unsigned NOT NULL DEFAULT 0 COMMENT '消息时间 Unix 时间戳',
`is_from_doctor` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否医生/医助侧发送',
`msg_type` varchar(32) NOT NULL DEFAULT '' COMMENT 'text/image/file/sound/video/custom/...',
`text` mediumtext COMMENT '文本或自定义消息 Data',
`image_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '图片 URL',
`file_url` varchar(1024) NOT NULL DEFAULT '' COMMENT '文件/语音/视频 URL',
`file_name` varchar(512) NOT NULL DEFAULT '' COMMENT '文件名',
`raw_elem_type` varchar(64) NOT NULL DEFAULT '' COMMENT 'TIM 元素类型',
`from_staff_name` varchar(64) NOT NULL DEFAULT '' COMMENT '医生侧姓名快照',
`doctor_peer_account` varchar(64) NOT NULL DEFAULT '' COMMENT '拉取会话时使用的医生侧账号 doctor_*',
`create_time` int unsigned NOT NULL DEFAULT 0 COMMENT '入库时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_msg_id` (`msg_id`),
KEY `idx_diagnosis_time` (`diagnosis_id`,`msg_time`),
KEY `idx_patient_time` (`patient_id`,`msg_time`),
KEY `idx_msg_time` (`msg_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='诊单IM聊天记录归档';