主要变更: 1. 所有 Entity/DTO/VO 添加 @Schema 注解,完善 API 文档 2. 新增前端 API 封装模块 (src/apis),包含 fetch.ts 和 apis.ts 3. 生成完整的 TypeScript 类型定义(100+ 个模型) 4. pom.xml 添加 Maven 编译配置和 UTF-8 编码支持 5. 更新 CLAUDE.md 开发文档,新增接口规范和 Swagger 注解规范 6. 清理旧的文档文件和 Flyway 迁移脚本 技术细节: - 后端:27 个实体类 + 所有 DTO/Response 添加 Swagger 注解 - 前端:新增 orval 生成的 API 客户端类型 - 构建:配置 Maven compiler plugin 和 Spring Boot 插件的 JVM 参数 - 数据库:新增 schema 导出文件,删除旧 Flyway 迁移脚本 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5.1 KiB
5.1 KiB
表名统一修改说明
修改时间
2026-03-10
修改目的
将数据库表名从复数形式改为单数形式,使其与 ORM 实体类名保持一致(除了下划线和驼峰的区别)。
修改内容
1. Flyway 迁移脚本
创建了新的 Flyway 迁移脚本:
- 文件:
reading-platform-java/src/main/resources/db/migration/V22__rename_tables_to_singular.sql - 功能:将所有数据库表名从复数改为单数
2. 实体类 @TableName 注解更新
更新了 36 个实体类的 @TableName 注解:
| 序号 | 原表名(复数) | 新表名(单数) | 实体类名 |
|---|---|---|---|
| 1 | admin_users |
admin_user |
AdminUser |
| 2 | tenants |
tenant |
Tenant |
| 3 | teachers |
teacher |
Teacher |
| 4 | students |
student |
Student |
| 5 | parents |
parent |
Parent |
| 6 | parent_students |
parent_student |
ParentStudent |
| 7 | classes |
clazz |
Clazz |
| 8 | class_teachers |
class_teacher |
ClassTeacher |
| 9 | student_class_history |
student_class_history |
StudentClassHistory (无需修改) |
| 10 | courses |
course |
Course |
| 11 | course_versions |
course_version |
CourseVersion |
| 12 | course_resources |
course_resource |
CourseResource |
| 13 | course_scripts |
course_script |
CourseScript |
| 14 | course_script_pages |
course_script_page |
CourseScriptPage |
| 15 | course_activities |
course_activity |
CourseActivity |
| 16 | course_packages |
course_package |
CoursePackage |
| 17 | school_courses |
school_course |
SchoolCourse |
| 18 | tenant_courses |
tenant_course |
TenantCourse |
| 19 | lessons |
lesson |
Lesson |
| 20 | lesson_feedbacks |
lesson_feedback |
LessonFeedback |
| 21 | student_records |
student_record |
StudentRecord |
| 22 | tasks |
task |
Task |
| 23 | task_targets |
task_target |
TaskTarget |
| 24 | task_completions |
task_completion |
TaskCompletion |
| 25 | task_templates |
task_template |
TaskTemplate |
| 26 | growth_records |
growth_record |
GrowthRecord |
| 27 | resource_libraries |
resource_library |
ResourceLibrary |
| 28 | resource_items |
resource_item |
ResourceItem |
| 29 | schedule_plans |
schedule_plan |
SchedulePlan |
| 30 | schedule_templates |
schedule_template |
ScheduleTemplate |
| 31 | system_settings |
system_setting |
SystemSetting |
| 32 | themes |
theme |
Theme |
| 33 | tags |
tag |
Tag |
| 34 | notifications |
notification |
Notification |
| 35 | operation_logs |
operation_log |
OperationLog |
3. Mapper 接口 SQL 更新
更新了以下 Mapper 接口中的硬编码 SQL 表名:
| 文件 | 修改内容 |
|---|---|
ThemeMapper.java |
DELETE FROM themes → DELETE FROM theme |
ParentMapper.java |
DELETE FROM parents → DELETE FROM parent |
TenantMapper.java |
DELETE FROM tenants → DELETE FROM tenant (2 处) |
TeacherMapper.java |
DELETE FROM teachers → DELETE FROM teacher |
StudentMapper.java |
DELETE FROM students → DELETE FROM student |
部署步骤
步骤 1:备份数据库
在执行迁移前,务必备份开发/生产数据库:
mysqldump -u root -p reading_platform > backup_$(date +%Y%m%d).sql
步骤 2:执行 Flyway 迁移
启动后端服务,Flyway 会自动执行 V22__rename_tables_to_singular.sql 迁移脚本。
或者手动执行:
mysql -u root -p reading_platform < reading-platform-java/src/main/resources/db/migration/V22__rename_tables_to_singular.sql
步骤 3:验证迁移结果
在 MySQL 中执行:
-- 查看所有表名
SHOW TABLES;
-- 验证特定表是否存在
SHOW TABLES LIKE 'student';
SHOW TABLES LIKE 'student_record';
SHOW TABLES LIKE 'lesson_feedback';
步骤 4:测试功能
启动后端服务后,测试以下功能:
- 用户管理(管理员、教师、学生、家长)
- 班级管理
- 课程管理
- 课时管理
- 任务管理
- 成长记录
- 资源管理
- 日程管理
注意事项
- 外键处理:迁移脚本中先禁用外键检查(
SET FOREIGN_KEY_CHECKS = 0),执行完后再启用 - Flyway 历史:确保
flyway_schema_history表正确记录迁移历史 - 生产环境:在生产环境执行前,务必在开发/测试环境充分测试
- 回滚方案:如需回滚,可以准备反向迁移脚本(将单数表名改回复数)
相关文件清单
新增文件
reading-platform-java/src/main/resources/db/migration/V22__rename_tables_to_singular.sql
修改的文件
- 所有 Entity 类(36 个文件)
- 5 个 Mapper 接口
验证清单
- 所有 Entity 类的
@TableName注解已更新 - 所有 Mapper 接口的 SQL 已更新
- Controller 中无硬编码表名引用
- Service 中无硬编码表名引用
- Flyway 迁移脚本已创建
后续工作
- 在开发环境执行迁移并验证
- 更新 API 文档中的表名引用(如有)
- 更新项目文档中的表名引用(如有)