feat: Sprint 1 - 数据正确性整改

P2-01: 移除 lifespan create_all,改为仅验证连接
       新增 /health/ready 就绪检查
P0-04: LLM 输出严格 Pydantic 校验
       - Agent 输出越界/非法 → parse_error
       - 预测输出自动修正 1X2 与比分一致性
P0-01: injuries cutoff 修复
       - get_injuries_for_match 增加 as_of 参数
       - injuries_slice 使用 as_of 过滤 retrieved_at
       - 防止回测时未来采集数据泄漏
P1-12: 批量入库优化
       - 预加载 teams 到内存 dict
       - 预加载 existing matches 到内存 set
       - 消灭 N+1 查询
This commit is contained in:
shangfangjian
2026-09-14 23:36:35 +08:00
parent 9b44905192
commit f3160e3062
11 changed files with 326 additions and 69 deletions
+12 -1
View File
@@ -53,6 +53,17 @@ async def get_db_read() -> AsyncIterator[AsyncSession]:
async def init_db() -> None:
"""开发/测试用:建表。生产建议用 alembic。"""
"""验证数据库连接(不建表)。
生产环境 schema 由 Alembic 管理。
本地开发/测试需要建表时调用 `create_all()`。
"""
async with engine.begin() as conn:
# 只验证连接,不自动建表
await conn.run_sync(lambda conn: None)
async def create_all() -> None:
"""创建所有表(仅用于本地开发/测试)。"""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)