移动端拍照上传、奥数区、学段约束解题与 AI 模型配置。
- 手机/平板响应式布局,支持拍照与相册上传 - 学生详情新增奥数区,按初/高中学段生成解法并禁止超纲 - 系统设置可配置 Ollama 或 OpenAI 兼容 API - 更新 frontend/dist 与使用说明
This commit is contained in:
@@ -7,7 +7,8 @@ from app.core.database import engine
|
||||
def run_migrations() -> None:
|
||||
"""Apply lightweight schema updates for existing databases."""
|
||||
inspector = inspect(engine)
|
||||
if "students" not in inspector.get_table_names():
|
||||
tables = set(inspector.get_table_names())
|
||||
if "students" not in tables:
|
||||
return
|
||||
|
||||
columns = {col["name"] for col in inspector.get_columns("students")}
|
||||
@@ -20,7 +21,7 @@ def run_migrations() -> None:
|
||||
)
|
||||
)
|
||||
|
||||
if "users" in inspector.get_table_names():
|
||||
if "users" in tables:
|
||||
user_columns = {col["name"] for col in inspector.get_columns("users")}
|
||||
if "is_superuser" not in user_columns:
|
||||
with engine.begin() as conn:
|
||||
@@ -33,3 +34,34 @@ def run_migrations() -> None:
|
||||
f"WHERE username = '{settings.ADMIN_DEFAULT_USERNAME}'"
|
||||
)
|
||||
)
|
||||
|
||||
if "wrong_questions" in tables:
|
||||
wq_columns = {col["name"] for col in inspector.get_columns("wrong_questions")}
|
||||
if "category" not in wq_columns:
|
||||
with engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
"ALTER TABLE wrong_questions ADD COLUMN category VARCHAR(32) "
|
||||
"NOT NULL DEFAULT 'regular'"
|
||||
)
|
||||
)
|
||||
|
||||
if "system_settings" in tables:
|
||||
ss_columns = {col["name"] for col in inspector.get_columns("system_settings")}
|
||||
alters: list[str] = []
|
||||
if "ai_provider" not in ss_columns:
|
||||
alters.append("ADD COLUMN ai_provider VARCHAR(16) NOT NULL DEFAULT 'ollama'")
|
||||
if "ollama_base_url" not in ss_columns:
|
||||
alters.append("ADD COLUMN ollama_base_url VARCHAR(256)")
|
||||
if "ollama_model" not in ss_columns:
|
||||
alters.append("ADD COLUMN ollama_model VARCHAR(128)")
|
||||
if "openai_base_url" not in ss_columns:
|
||||
alters.append("ADD COLUMN openai_base_url VARCHAR(256)")
|
||||
if "openai_model" not in ss_columns:
|
||||
alters.append("ADD COLUMN openai_model VARCHAR(128)")
|
||||
if "openai_api_key" not in ss_columns:
|
||||
alters.append("ADD COLUMN openai_api_key VARCHAR(512)")
|
||||
if alters:
|
||||
with engine.begin() as conn:
|
||||
for clause in alters:
|
||||
conn.execute(text(f"ALTER TABLE system_settings {clause}"))
|
||||
|
||||
Reference in New Issue
Block a user