-- 为 t_medication_records 表添加 reminder_sent 字段
-- 用于标记该条服药记录是否已经发送了提醒通知

ALTER TABLE `t_medication_records`
ADD COLUMN `reminder_sent` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已发送提醒' AFTER `deleted`;

-- 为已存在的记录设置默认值
UPDATE `t_medication_records` SET `reminder_sent` = 0 WHERE `reminder_sent` IS NULL;

-- 添加索引以优化查询性能（查询未发送提醒的记录）
CREATE INDEX `idx_reminder_sent_status_scheduled` ON `t_medication_records` (`reminder_sent`, `status`, `scheduled_time`);