Files
whale-town-end/src/business/notice/migrations/create-notices-table.sql
moyin 874ccfa879 db:添加通知系统数据库支持
- 创建notices表结构SQL脚本
- 包含完整的字段定义和索引优化
- 添加通知服务单元测试用例
2026-01-10 21:52:48 +08:00

21 lines
1.2 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.
-- 创建通知表
CREATE TABLE IF NOT EXISTS `notices` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL COMMENT '通知标题',
`content` text NOT NULL COMMENT '通知内容',
`type` enum('system','user','broadcast') NOT NULL DEFAULT 'system' COMMENT '通知类型',
`status` enum('pending','sent','read','failed') NOT NULL DEFAULT 'pending' COMMENT '通知状态',
`userId` int DEFAULT NULL COMMENT '接收者用户IDNULL表示广播',
`senderId` int DEFAULT NULL COMMENT '发送者用户ID',
`scheduledAt` datetime DEFAULT NULL COMMENT '计划发送时间',
`sentAt` datetime DEFAULT NULL COMMENT '实际发送时间',
`readAt` datetime DEFAULT NULL COMMENT '阅读时间',
`metadata` json DEFAULT NULL COMMENT '额外数据',
`createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间',
`updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_notices_user_id` (`userId`),
KEY `idx_notices_status` (`status`),
KEY `idx_notices_scheduled_at` (`scheduledAt`),
KEY `idx_notices_created_at` (`createdAt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='通知表';