feat(db): moments_post 表+upsert(朋友圈实体,PK=云客data.id,create_time统一ms)
- MomentsPost 模型:moments_post 表,PK=id(云客 getFriendsterInfo data.id), wechat_id/create_time 建索引,praise/comment/image 存 JSON 列 - 迁移 524da8d2d597(手写 create_table,已应用到 smoke.db 并在临时 SQLite 全链路 upgrade/downgrade 验证) - repos.upsert_moments_posts:批量幂等 upsert;附带修 _build_column_values 对 JSON 列表的误 join(标量列 join 保持不变,dept_route 旧测试仍过) - 修复 3 个 chat_group 旧测试缺 owner_account_id(2026-08-24 复合主键遗留) - 全套 430 测试通过 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -269,3 +269,51 @@ async def test_group_member_composite_pk():
|
||||
assert fetched.nickname == "Bob"
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
async def test_moments_post_round_trip():
|
||||
"""A MomentsPost row round-trips JSON list columns + ms create_time."""
|
||||
from app.db.models import MomentsPost
|
||||
|
||||
engine = await _make_engine()
|
||||
try:
|
||||
SessionLocal = async_sessionmaker(engine, expire_on_commit=False)
|
||||
async with SessionLocal() as session:
|
||||
row = MomentsPost(
|
||||
id="69e082a3c3524a7fe3ac53b4",
|
||||
wechat_id="wxid_x",
|
||||
sns_id="-3546042415332912522",
|
||||
author_name="Yoyo",
|
||||
author_wxid="wxid_x",
|
||||
author_avatar="https://wx.qlogo.cn/avatars/yoyo",
|
||||
content="Welcome to HESU",
|
||||
type_raw="1",
|
||||
create_time=1776302051000,
|
||||
praise_json=[{"name": "E**U"}],
|
||||
comment_json=[],
|
||||
image_urls=["https://wx.oss.example/a.jpg"],
|
||||
raw_json={"id": "69e082a3c3524a7fe3ac53b4"},
|
||||
)
|
||||
session.add(row)
|
||||
await session.commit()
|
||||
|
||||
fetched = (
|
||||
await session.execute(
|
||||
sa.select(MomentsPost).where(
|
||||
MomentsPost.id == "69e082a3c3524a7fe3ac53b4"
|
||||
)
|
||||
)
|
||||
).scalar_one()
|
||||
assert fetched.wechat_id == "wxid_x"
|
||||
assert fetched.sns_id == "-3546042415332912522"
|
||||
# JSON list columns must round-trip as lists (not joined strings).
|
||||
assert fetched.praise_json[0]["name"] == "E**U"
|
||||
assert fetched.comment_json == []
|
||||
assert fetched.image_urls == ["https://wx.oss.example/a.jpg"]
|
||||
# create_time stays the ms-epoch int exactly as written.
|
||||
assert fetched.create_time == 1776302051000
|
||||
assert fetched.type_raw == "1"
|
||||
assert fetched.raw_json == {"id": "69e082a3c3524a7fe3ac53b4"}
|
||||
assert fetched.fetched_at is not None
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
Reference in New Issue
Block a user