修复学期功能
This commit is contained in:
112
sql/init.sql
112
sql/init.sql
@@ -187,6 +187,13 @@ CREATE TABLE IF NOT EXISTS `semester_archives` (
|
||||
`final_points` INT NOT NULL COMMENT '学期最终操行分',
|
||||
`rank_position` INT DEFAULT NULL COMMENT '排名',
|
||||
`total_students` INT DEFAULT NULL COMMENT '班级总人数',
|
||||
`attendance_present` INT DEFAULT 0 COMMENT '出勤次数',
|
||||
`attendance_absent` INT DEFAULT 0 COMMENT '缺勤次数',
|
||||
`attendance_late` INT DEFAULT 0 COMMENT '迟到次数',
|
||||
`attendance_leave` INT DEFAULT 0 COMMENT '请假次数',
|
||||
`homework_submitted` INT DEFAULT 0 COMMENT '已交作业数',
|
||||
`homework_not_submitted` INT DEFAULT 0 COMMENT '未交作业数',
|
||||
`homework_late` INT DEFAULT 0 COMMENT '迟交作业数',
|
||||
`archived_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`semester_id`) REFERENCES `semesters`(`semester_id`),
|
||||
FOREIGN KEY (`student_id`) REFERENCES `students`(`student_id`)
|
||||
@@ -260,6 +267,111 @@ PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_present 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_present'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_present` INT DEFAULT 0 COMMENT ''出勤次数'' AFTER `total_students`',
|
||||
'SELECT ''semester_archives.attendance_present already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_absent 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_absent'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_absent` INT DEFAULT 0 COMMENT ''缺勤次数'' AFTER `attendance_present`',
|
||||
'SELECT ''semester_archives.attendance_absent already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_late 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_late'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_late` INT DEFAULT 0 COMMENT ''迟到次数'' AFTER `attendance_absent`',
|
||||
'SELECT ''semester_archives.attendance_late already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 attendance_leave 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'attendance_leave'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `attendance_leave` INT DEFAULT 0 COMMENT ''请假次数'' AFTER `attendance_late`',
|
||||
'SELECT ''semester_archives.attendance_leave already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 homework_submitted 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'homework_submitted'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `homework_submitted` INT DEFAULT 0 COMMENT ''已交作业数'' AFTER `attendance_leave`',
|
||||
'SELECT ''semester_archives.homework_submitted already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 homework_not_submitted 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'homework_not_submitted'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `homework_not_submitted` INT DEFAULT 0 COMMENT ''未交作业数'' AFTER `homework_submitted`',
|
||||
'SELECT ''semester_archives.homework_not_submitted already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 迁移:semester_archives 表新增 homework_late 字段
|
||||
SET @column_exists = (
|
||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = 'classmanagerdb'
|
||||
AND TABLE_NAME = 'semester_archives'
|
||||
AND COLUMN_NAME = 'homework_late'
|
||||
);
|
||||
SET @sql = IF(@column_exists = 0,
|
||||
'ALTER TABLE `semester_archives` ADD COLUMN `homework_late` INT DEFAULT 0 COMMENT ''迟交作业数'' AFTER `homework_not_submitted`',
|
||||
'SELECT ''semester_archives.homework_late already exists'' AS message'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- 插入初始科目(仅语数英,如不存在)
|
||||
INSERT IGNORE INTO `subjects` (`subject_name`, `subject_code`, `sort_order`) VALUES
|
||||
('语文', 'CHI', 1),
|
||||
|
||||
Reference in New Issue
Block a user