refactor(management): 种子函数移入management包+深拷贝冻结配置+清理死代码

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-09 17:06:14 +08:00
parent afc71e61ef
commit 8b555a5ad4
3 changed files with 42 additions and 35 deletions
+3 -33
View File
@@ -17,6 +17,7 @@ Three invocations (plus analytics backfills, see below)::
python -m app.sync.cli sensitive-scan --full
python -m app.sync.cli first-reply-facts
python -m app.sync.cli employee-metrics
python -m app.sync.cli score-config
Auth + DB
---------
@@ -471,43 +472,12 @@ async def _cmd_employee_metrics(args: argparse.Namespace) -> int:
await engine.dispose()
async def _seed_score_config(session) -> str | None:
"""种子默认评分配置;已存在同版本返回 None(幂等)。纯会话函数可测。"""
from app.db.models import EmployeeScoreConfig
from app.management.metric_definitions import (
DEFAULT_SCORE_CONFIG,
validate_config,
)
problems = validate_config(DEFAULT_SCORE_CONFIG)
if problems:
raise ValueError(f"score config invalid: {problems}")
exists = (
await session.execute(
sa.select(EmployeeScoreConfig.id).where(
EmployeeScoreConfig.version == DEFAULT_SCORE_CONFIG["version"]
)
)
).scalar_one_or_none()
if exists is not None:
return None
session.add(
EmployeeScoreConfig(
version=DEFAULT_SCORE_CONFIG["version"],
name=DEFAULT_SCORE_CONFIG["name"],
status="active",
config_json=DEFAULT_SCORE_CONFIG,
created_by="seed-cli",
)
)
await session.flush()
return DEFAULT_SCORE_CONFIG["version"]
async def _cmd_score_config(args: argparse.Namespace) -> int:
settings = get_settings()
engine, session_maker = await _init_db(settings.db_url)
try:
from app.management.metric_definitions import _seed_score_config
async with session_maker() as session:
version = await _seed_score_config(session)
await session.commit()