安全加固 + 数据管线修复 + 质量改进(第2批)
安全加固: - /api/v1/predict 限流改用 get_client_ip 防 X-Forwarded-For 伪造 - 新增 TRUST_PROXY_HEADERS/REQUIRE_ADMIN_AUTH 配置,默认 fail-closed - 生产环境管理接口未配置鉴权时拒绝(503),不再放行 数据管线修复: - injuries IntegrityError 改用 begin_nested(SAVEPOINT)隔离批次 - injuries 空名单 vs 未配置语义区分(has_data 精确标记) - bzzoiro 统计字段映射(shots/possession/cards) + 入库条件放宽 - available_at 语义收紧(回测防泄漏) - team_names NFKD 去变音双重查找 + 补齐变体键 预测系统改进: - multi-agent 全专家失败时 status=degraded 跳过终裁 - agent_weights 独立持久化到 predictions 表 新增迁移: - 0014_predictions_agent_weights.py 新增测试(8个文件): - test_ip_spoofing.py: 限流防伪造 - test_require_admin_fail_closed.py: 生产 fail-closed - test_injuries_integrity_rollback.py: SAVEPOINT 隔离 - test_injuries_slice_semantic.py: 空名单 vs 未配置 - test_available_at.py: 回测防泄漏 - test_bzzoirot_stats.py: 统计字段映射 - test_team_names_normalize.py: NFKD 变体 - test_multi_agent_degraded.py: 全失败 degraded - test_agent_weights_persist.py: 权重持久化
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""为 predictions 表增加 agent_weights 列
|
||||
|
||||
Revision ID: 0014_predictions_agent_weights
|
||||
Revises: 0013_predictions_unique_constraint_mode_run_type
|
||||
Create Date: 2026-09-20
|
||||
|
||||
背景:
|
||||
multi-agent 终裁的 agent_weights 原本只在 raw_response JSON 中,
|
||||
无独立列,评估不便。本迁移增加 agent_weights JSONB 列,可空,旧行保持 NULL。
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '0014_predictions_agent_weights'
|
||||
down_revision: Union[str, None] = '0013_predictions_unique_constraint_mode_run_type'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# 新增 agent_weights 列(JSONB, 可空, 旧行保持 NULL)
|
||||
op.add_column(
|
||||
"predictions",
|
||||
sa.Column(
|
||||
"agent_weights",
|
||||
sa.dialects.postgresql.JSONB(),
|
||||
nullable=True,
|
||||
comment="multi-agent 终裁各专家权重, 格式: {expert_name: weight}",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# 删除 agent_weights 列
|
||||
op.drop_column("predictions", "agent_weights")
|
||||
Reference in New Issue
Block a user