Files
plates-server/sql-scripts/mood-checkins-table-create.sql
richarjiang f26d8e64c6 feat: 新增心情打卡功能模块
实现心情打卡的完整功能,包括数据库表设计、API接口、业务逻辑和文档说明。支持记录多种心情类型、强度评分和统计分析功能。
2025-08-21 15:20:05 +08:00

24 lines
1.5 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 `t_mood_checkins` (
`id` varchar(36) NOT NULL COMMENT '主键ID',
`user_id` varchar(255) NOT NULL COMMENT '用户ID',
`mood_type` enum('happy','excited','thrilled','calm','anxious','sad','lonely','wronged','angry','tired') NOT NULL COMMENT '心情类型:开心、心动、兴奋、平静、焦虑、难过、孤独、委屈、生气、心累',
`intensity` int NOT NULL DEFAULT '5' COMMENT '心情强度1-10',
`description` text COMMENT '心情描述',
`checkin_date` date NOT NULL COMMENT '打卡日期YYYY-MM-DD',
`metadata` json DEFAULT NULL COMMENT '扩展数据(标签、触发事件等)',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除',
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_checkin_date` (`checkin_date`),
KEY `idx_mood_type` (`mood_type`),
KEY `idx_user_date` (`user_id`, `checkin_date`),
KEY `idx_deleted` (`deleted`),
CONSTRAINT `fk_mood_checkins_user_id` FOREIGN KEY (`user_id`) REFERENCES `t_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='心情打卡表';
-- 添加索引以优化查询性能
CREATE INDEX `idx_user_mood_date` ON `t_mood_checkins` (`user_id`, `mood_type`, `checkin_date`);
CREATE INDEX `idx_intensity` ON `t_mood_checkins` (`intensity`);