优化考勤记录
This commit is contained in:
30
sql/init.sql
30
sql/init.sql
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user