feat(retention): 删除用户/Key 时保留历史记录,外键改 SET NULL 并添加名称快照

- Usage/RequestCandidate/VideoTask/Stats 等表的 user_id/api_key_id 外键从
  CASCADE 改为 SET NULL,删除用户或 Key 后历史记录不再丢失
- 各表添加 username/api_key_name 快照字段,删除后仍可追溯归属
- 新增 bulk_cleanup 模块,分批置空大表外键避免长事务锁
- 删除用户/Key 流程集成预清理步骤,先置空再删除
- 精简 candidate_builder 冗余 debug 日志
- 修复 proxy_nodes 启动日志 format 占位符错误({} -> %s)
- 前端批量操作请求增加 5 分钟超时配置
This commit is contained in:
fawney19
2026-03-08 14:31:15 +08:00
parent 25c33846be
commit bd3f73c2fc
26 changed files with 799 additions and 96 deletions

View File

@@ -0,0 +1,29 @@
from __future__ import annotations
from unittest.mock import MagicMock
from src.services.request.candidate import RequestCandidateService
def test_create_candidate_persists_snapshot_fields() -> None:
db = MagicMock()
candidate = RequestCandidateService.create_candidate(
db=db,
request_id="req-1",
candidate_index=0,
retry_index=1,
user_id="user-1",
api_key_id="key-1",
username="alice",
api_key_name="Primary Key",
provider_id="provider-1",
endpoint_id="endpoint-1",
key_id="pool-key-1",
status="available",
)
assert candidate.username == "alice"
assert candidate.api_key_name == "Primary Key"
db.add.assert_called_once_with(candidate)
db.flush.assert_called_once()