-- 0021_attendance_period.sql -- L-6 节次考勤:为 attendance_records 表添加 period 字段。 -- -- 节次枚举: -- morning_reading 早读 -- morning 上午 -- afternoon 下午 -- evening 晚自习 -- full_day 全日(默认值,向后兼容:null 也表示全日) -- -- 向后兼容策略: -- - 新增 period 列为 NULLABLE,已有数据保持 NULL(视为 full_day) -- - 新记录由应用层显式写入 period;未指定时写入 'full_day' -- - 查询层 period IS NULL OR period = 'full_day' 均视为全日记录 ALTER TABLE `attendance_records` ADD COLUMN `period` ENUM('morning_reading','morning','afternoon','evening','full_day') NULL DEFAULT NULL AFTER `date`; -- 复合索引:班级 + 日期 + 节次,支持按节次查询班级当日点名 CREATE INDEX `attendance_records_class_date_period_idx` ON `attendance_records` (`class_id`, `date`, `period`);