-- 心情打卡表
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`);