优化考勤记录

This commit is contained in:
2026-04-27 01:36:23 +08:00
parent 439c074534
commit 17cc08071c
7 changed files with 119 additions and 47 deletions

View File

@@ -267,6 +267,36 @@ PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- attendance_records 表:添加 slot 字段(如不存在)
SET @column_exists = (
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'classmanagerdb'
AND TABLE_NAME = 'attendance_records'
AND COLUMN_NAME = 'slot'
);
SET @sql = IF(@column_exists = 0,
'ALTER TABLE `attendance_records` ADD COLUMN `slot` VARCHAR(20) DEFAULT ''morning'' COMMENT ''时段: morning/afternoon/evening'' AFTER `date`',
'SELECT ''attendance_records.slot already exists'' AS message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 删除旧唯一键并添加新唯一键含slot
SET @uk_exists = (
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'classmanagerdb'
AND TABLE_NAME = 'attendance_records'
AND CONSTRAINT_NAME = 'uk_student_date'
);
SET @sql = IF(@uk_exists > 0,
'ALTER TABLE `attendance_records` DROP INDEX `uk_student_date`, ADD UNIQUE KEY `uk_student_date_slot` (`student_id`, `date`, `slot`)',
'SELECT ''uk_student_date does not exist, skipping'' AS message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 迁移semester_archives 表新增 attendance_present 字段
SET @column_exists = (
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS