feat(P2余量+P3): chat/history+usage聚合API;教师端:is_admin+班级模型+admin API(班级/加学生/发题公告插对话流/学情聚合/看对话/用量)+teacher.html教师工作台+index历史对话加载+教师入口
这个提交包含在:
@@ -38,6 +38,8 @@ class Settings(BaseSettings):
|
||||
mongo_uri: str = "mongodb://hydro:change-me@127.0.0.1:27017/hydro"
|
||||
# 新用户默认学科(注册未指定时)
|
||||
default_course: str = "usaco"
|
||||
# 管理员用户名(注册/登录时自动授予 is_admin;逗号分隔)
|
||||
admin_usernames: str = "langxm"
|
||||
|
||||
# ---- 判题引擎:hydro | judge0 | local ----
|
||||
judge_engine: str = "hydro"
|
||||
|
||||
+14
-1
@@ -29,7 +29,7 @@ def get_session():
|
||||
|
||||
def init_db(url: str | None = None) -> None:
|
||||
"""建表(启动时调用)。"""
|
||||
from app.models import message, problem, progress, submission, user # noqa: F401 确保模型注册
|
||||
from app.models import klass, message, problem, progress, submission, user # noqa: F401 确保模型注册
|
||||
|
||||
global engine, SessionLocal
|
||||
if url and url != settings.database_url:
|
||||
@@ -39,3 +39,16 @@ def init_db(url: str | None = None) -> None:
|
||||
)
|
||||
SessionLocal = sessionmaker(bind=engine, autoflush=False, expire_on_commit=False)
|
||||
Base.metadata.create_all(engine)
|
||||
_migrate()
|
||||
|
||||
|
||||
def _migrate() -> None:
|
||||
"""小步迁移:老库加列(is_admin)。幂等:列已存在时忽略。"""
|
||||
if not settings.database_url.startswith("sqlite"):
|
||||
return
|
||||
from sqlalchemy import text
|
||||
|
||||
with engine.begin() as conn:
|
||||
cols = {r[1] for r in conn.execute(text("PRAGMA table_info(users)"))}
|
||||
if "is_admin" not in cols:
|
||||
conn.execute(text("ALTER TABLE users ADD COLUMN is_admin INTEGER DEFAULT 0"))
|
||||
|
||||
在新工单中引用
屏蔽一个用户