|
@@ -570,6 +570,51 @@ public class DatabaseInitializer implements CommandLineRunner {
|
|
|
// 索引已存在,忽略错误
|
|
// 索引已存在,忽略错误
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 迁移10: users表添加teacherFamilyIds字段(指导师关联的家庭ID列表)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE users ADD COLUMN teacher_family_ids VARCHAR(500) COMMENT '指导师关联的家庭ID列表(逗号分隔)'");
|
|
|
|
|
+ log.info("已添加teacher_family_ids列到users表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移11: families表添加teacherId字段(绑定的指导师ID)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE families ADD COLUMN teacher_id BIGINT COMMENT '绑定的指导师ID'");
|
|
|
|
|
+ log.info("已添加teacher_id列到families表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE families ADD INDEX idx_teacher_id (teacher_id)");
|
|
|
|
|
+ log.info("已添加idx_teacher_id索引到families表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 索引已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移12: 创建 teacher_messages 表(家长咨询指导师)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS teacher_messages (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "family_id BIGINT NOT NULL COMMENT '家庭ID', " +
|
|
|
|
|
+ "parent_id BIGINT NOT NULL COMMENT '家长用户ID', " +
|
|
|
|
|
+ "teacher_id BIGINT NOT NULL COMMENT '指导师用户ID', " +
|
|
|
|
|
+ "content TEXT NOT NULL COMMENT '消息内容', " +
|
|
|
|
|
+ "reply_content TEXT COMMENT '回复内容', " +
|
|
|
|
|
+ "status VARCHAR(20) DEFAULT 'pending' COMMENT '状态:pending(待回复)/replied(已回复)', " +
|
|
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "replied_at DATETIME COMMENT '回复时间', " +
|
|
|
|
|
+ "INDEX idx_family_id (family_id), " +
|
|
|
|
|
+ "INDEX idx_teacher_id (teacher_id), " +
|
|
|
|
|
+ "INDEX idx_parent_id (parent_id), " +
|
|
|
|
|
+ "INDEX idx_status (status)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
|
|
|
|
+ log.info("已创建teacher_messages表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 表已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
log.info("数据库迁移完成");
|
|
log.info("数据库迁移完成");
|
|
|
}
|
|
}
|
|
|
|
|
|