M2b:删除旧 chat 体系——线性会话/叩心/情绪/纪念日模型与页面退役(迁移 003 双向验证),runs 去会话外键,测试全量修剪
This commit is contained in:
1 parent
5f36e3785c
commit
ad9c9e942a
22 files changed
+424
-427
No files matched your search
@@ -10,7 +10,6 @@ from app.core.time import utc_now
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.character import Character
|
||||
from app.models.personality import PersonalityVersion
|
||||
from app.models.time_anniversary import TimeAnniversary
|
||||
from app.modules.character import (
|
||||
MODEL_POLICY_CREATE_DEFAULTS,
|
||||
SYSTEM_TEMPLATE_OWNER_SCOPE,
|
||||
@@ -19,7 +18,6 @@ from app.modules.character import (
|
||||
)
|
||||
from app.repositories import characters as character_repo
|
||||
from app.repositories import personality as personality_repo
|
||||
from app.repositories import time_anniversaries as anniversary_repo
|
||||
from app.repositories.json_utils import dumps, loads_dict
|
||||
from app.schemas.character import (
|
||||
ActivateCharacterResponse,
|
||||
@@ -232,7 +230,7 @@ async def create_character_from_template(
|
||||
session: AsyncSession, template: Character, owner_scope: str
|
||||
) -> Character:
|
||||
# 模板的 birthday 仅在兜底(空/缺失)时不继承;显式设置的有效生日原样保留,
|
||||
# 由 _ensure_default_birthday 写入子角色的 profile 与 time_anniversaries 表。
|
||||
# 由 _ensure_default_birthday 写入子角色的 profile。
|
||||
profile = loads_dict(template.profile_json)
|
||||
birthday = profile.get("birthday")
|
||||
if not (isinstance(birthday, str) and birthday.strip()):
|
||||
@@ -388,51 +386,17 @@ async def _audit_character(session: AsyncSession, character: Character, action:
|
||||
|
||||
|
||||
async def _ensure_default_birthday(session: AsyncSession, character: Character) -> None:
|
||||
"""birthday 缺失时用 created_at 兜底:写 profile.birthday 并建一条生日纪念日。
|
||||
"""birthday 缺失时用 created_at 兜底:仅写 profile.birthday。
|
||||
|
||||
- 仅在 profile.birthday 为空/缺失时触发默认兜底;用户或模板已设则不覆盖。
|
||||
- 无论 birthday 是否已设,只要角色尚无 birthday 纪念日,就建一条。
|
||||
- profile.birthday 与 TimeAnniversary.date 取 birthday 值(显式)或 created_at 的 ISO 日期。
|
||||
- 须在 character flush 后调用(依赖 id 与 created_at);同一事务内随外层 commit 落库。
|
||||
纪念日表(time_anniversaries)随旧时间模型退役删除;辰正(M8 重实现)落地后
|
||||
生日提醒改由时态感知按 profile.birthday 计算,不再预写行。
|
||||
"""
|
||||
profile = loads_dict(character.profile_json)
|
||||
birthday = profile.get("birthday")
|
||||
if isinstance(birthday, str) and birthday.strip():
|
||||
# birthday 已设但可能无对应纪念日(如从模板继承),仅 ISO 格式生日补建
|
||||
existing = await anniversary_repo.list_anniversaries(session, character.id)
|
||||
if not any(a.kind == "birthday" for a in existing):
|
||||
try:
|
||||
datetime.strptime(birthday, "%Y-%m-%d")
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
else:
|
||||
anniversary = TimeAnniversary(
|
||||
character_id=character.id,
|
||||
name=f"{character.display_name or character.name}·生辰",
|
||||
calendar="solar",
|
||||
date=birthday,
|
||||
recurs_yearly=True,
|
||||
kind="birthday",
|
||||
subject_type="character_self",
|
||||
source="auto",
|
||||
)
|
||||
await anniversary_repo.create_anniversary(session, anniversary)
|
||||
return
|
||||
birthday_iso = character.created_at.strftime("%Y-%m-%d")
|
||||
profile["birthday"] = birthday_iso
|
||||
profile["birthday"] = character.created_at.strftime("%Y-%m-%d")
|
||||
character.profile_json = dumps(profile)
|
||||
anniversary = TimeAnniversary(
|
||||
character_id=character.id,
|
||||
name=f"{character.display_name or character.name}·生辰",
|
||||
calendar="solar",
|
||||
date=birthday_iso,
|
||||
recurs_yearly=True,
|
||||
kind="birthday",
|
||||
subject_type="character_self",
|
||||
source="auto",
|
||||
)
|
||||
await anniversary_repo.create_anniversary(session, anniversary)
|
||||
|
||||
|
||||
async def create_character(
|
||||
session: AsyncSession,
|
||||
|
||||
Reference in new issue
Block a user