Files
hfb_sys/backend/migrations/000088_sms_messages.sql
T

34 lines
2.1 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.
-- +goose Up
-- 节点短信:业务节点触发触达的短信发送队列。
-- 业务事务内只写 pending 记录(与站内信 notification.Append 同点),
-- 由后台任务 smsdispatch 异步发送,短信失败不回滚业务、也不阻塞接口。
-- 唯一索引保证「同一业务对象 + 同一节点 + 同一接收人」只发一次,
-- 同时充当节点级幂等去重(上架三天未成交提醒不会重复轰炸号主)。
CREATE TABLE IF NOT EXISTS sms_messages (
id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '接收用户 ID',
phone VARCHAR(32) NOT NULL DEFAULT '' COMMENT '接收手机号快照',
node VARCHAR(64) NOT NULL COMMENT '业务节点标识,如 listing_review_rejected',
biz_type VARCHAR(32) NOT NULL DEFAULT '' COMMENT '业务类型: listing/order/pickup 等',
biz_id BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '业务对象 ID',
distribution_site_id BIGINT UNSIGNED NULL COMMENT '归属分销站点 ID,NULL 表示主站',
template_code VARCHAR(64) NOT NULL DEFAULT '' COMMENT '实际使用的模板 CODE 快照',
template_params JSON NULL COMMENT '模板变量快照',
sign_name VARCHAR(64) NOT NULL DEFAULT '' COMMENT '实际使用的短信签名快照',
status VARCHAR(16) NOT NULL DEFAULT 'pending' COMMENT 'pending/sent/failed/skipped',
skip_reason VARCHAR(128) NOT NULL DEFAULT '' COMMENT '未发送原因(节点未启用/未配置模板等)',
retry_count INT NOT NULL DEFAULT 0 COMMENT '已重试次数',
last_error VARCHAR(512) NOT NULL DEFAULT '' COMMENT '最后一次发送失败原因',
sent_at DATETIME NULL COMMENT '发送成功时间',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uk_sms_messages_node_biz_user (node, biz_type, biz_id, user_id),
KEY idx_sms_messages_status_id (status, id),
KEY idx_sms_messages_site_id (distribution_site_id, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='节点短信发送队列';
-- +goose Down
DROP TABLE IF EXISTS sms_messages;