feat: 目标和问题统一分类体系(综合/乐理相关/演奏能力/其他),添加数据库迁移

This commit is contained in:
hmo
2026-04-23 21:57:00 +08:00
parent 5f1dcc08fb
commit f83769fa20
4 changed files with 49 additions and 6 deletions
+23
View File
@@ -131,6 +131,29 @@ def create_app():
if "level" not in goal_columns:
db.session.execute(text("ALTER TABLE goals ADD COLUMN level VARCHAR(20) DEFAULT '入门'"))
db.session.commit()
# 检查goals表是否有category字段
if "category" not in goal_columns:
db.session.execute(text("ALTER TABLE goals ADD COLUMN category VARCHAR(20) DEFAULT '综合'"))
db.session.commit()
# 迁移problems表分类:旧分类 -> 新分类
# 技术类/技术类(手型)/技术类(生理限制) -> 演奏能力
# 识谱类 -> 乐理相关
# 综合类 -> 综合类 (保持不变)
# 其他 -> 其他 (保持不变)
category_mapping = {
'技术类': '演奏能力',
'技术类(手型)': '演奏能力',
'技术类(生理限制)': '演奏能力',
'识谱类': '乐理相关',
}
for old_cat, new_cat in category_mapping.items():
db.session.execute(
text("UPDATE problems SET category = :new_cat WHERE category = :old_cat"),
{"new_cat": new_cat, "old_cat": old_cat}
)
db.session.commit()
except Exception as e:
print(f"数据库迁移: {e}")