refactor(database): 迁移到SQLite并清理旧MySQL相关代码

移除MySQL相关依赖和配置,完全迁移到SQLite数据库
删除不再需要的MySQL迁移脚本和备份文件
更新README文档说明新的数据库架构
在init_db.js中整合教师和系统设置表的初始化逻辑
This commit is contained in:
祀梦
2025-12-23 00:02:44 +08:00
parent 84d5840391
commit e63ef0af0a
13 changed files with 193 additions and 761 deletions

View File

@@ -28,6 +28,13 @@ const insertStudent = async (student) => {
);
};
const insertTeacher = async (teacher) => {
await run(
'INSERT INTO teachers (id, name, department, title, contact_info) VALUES (?, ?, ?, ?, ?)',
[teacher.id, teacher.name, teacher.department, teacher.title, teacher.contact_info]
);
};
const insertClass = async (cls) => {
return await run(
'INSERT INTO classes (class_name, grade, major, teacher_id) VALUES (?, ?, ?, ?)',
@@ -91,6 +98,8 @@ const init = async () => {
await run('DROP TABLE IF EXISTS students');
await run('DROP TABLE IF EXISTS users');
await run('DROP TABLE IF EXISTS operation_logs');
await run('DROP TABLE IF EXISTS system_settings');
await run('DROP TABLE IF EXISTS teachers');
// Create tables
console.log('创建表结构...');
@@ -174,8 +183,38 @@ const init = async () => {
)
`);
await run(`
CREATE TABLE teachers (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
department TEXT,
title TEXT,
contact_info TEXT,
FOREIGN KEY (id) REFERENCES users(id) ON DELETE CASCADE
)
`);
await run(`
CREATE TABLE system_settings (
key TEXT PRIMARY KEY,
value TEXT
)
`);
console.log('生成基础数据...');
// 0. System Settings
const defaultSettings = [
['system_name', '学校成绩管理系统'],
['current_semester', '2023-2024-2'],
['allow_course_selection', '1'],
['allow_grade_check', '1']
];
for (const [key, value] of defaultSettings) {
await run('INSERT OR IGNORE INTO system_settings (key, value) VALUES (?, ?)', [key, value]);
}
// 1. Admin
await insertUser({
id: 'admin',
@@ -187,9 +226,16 @@ const init = async () => {
// 2. Teachers (20 teachers)
const teachers = [];
const departments = ['计算机学院', '软件学院', '信息工程学院', '理学院', '外国语学院'];
const titles = ['教授', '副教授', '讲师', '助教'];
for (let i = 1; i <= 20; i++) {
const id = `T${1000 + i}`;
const name = `教师${String.fromCharCode(65 + (i % 26))}${i}`;
const dept = departments[i % departments.length];
const title = titles[i % titles.length];
const contact = `139${Math.floor(Math.random() * 90000000 + 10000000)}`;
await insertUser({
id,
name,
@@ -197,6 +243,15 @@ const init = async () => {
role: 'teacher',
class: null
});
await insertTeacher({
id,
name,
department: dept,
title: title,
contact_info: contact
});
teachers.push(id);
}