fix: 将平台业务ID统一改为String并自动建表

- 抖音、B站、快手、微博的帖子/视频/评论ID从BigInteger改为String,
  避免PostgreSQL下字符串写入BIGINT报错及未来ID溢出风险
- B站dynamic_id改为String,修复API返回id_str被强转int导致的精度丢失
- 知乎提取器对content_id/question_id显式str()转换
- main.py启动数据库保存模式时自动建表,无需手动--init_db
- 同步更新相关老化测试
This commit is contained in:
程序员阿江(Relakkes)
2026-07-01 23:03:43 +08:00
parent 51d4853db5
commit a06273ea6c
11 changed files with 55 additions and 61 deletions
+4 -4
View File
@@ -282,7 +282,7 @@ def test_douyin_store_end_to_end_sqlite(monkeypatch):
# dict 多了已删列会 TypeError,少了非空必填列 SQLAlchemy 也会报错;
# 此处证明 captured 的 key 与删列后 ORM 列完全对得上,不抛异常。
obj = DouyinAweme(**captured)
assert int(obj.aweme_id) == int(aweme["aweme_id"])
assert obj.aweme_id == aweme["aweme_id"]
assert obj.creator_hash == anonymize_user_id(raw_uid)
assert obj.creator_hash != raw_uid
assert obj.nickname == mask_nickname(raw_nick)
@@ -310,7 +310,7 @@ def test_douyin_store_end_to_end_sqlite(monkeypatch):
# 查询回读
async with db_session.get_session() as session:
res = await session.execute(
select(DouyinAweme).where(DouyinAweme.aweme_id == int(aweme["aweme_id"]))
select(DouyinAweme).where(DouyinAweme.aweme_id == aweme["aweme_id"])
)
row = res.scalar_one_or_none()
await engine.dispose()
@@ -320,7 +320,7 @@ def test_douyin_store_end_to_end_sqlite(monkeypatch):
# ---- 4. 回读断言 ----
assert row is not None, "作品未写入 SQLite"
assert int(row.aweme_id) == int(aweme["aweme_id"])
assert row.aweme_id == aweme["aweme_id"]
assert row.creator_hash == anonymize_user_id(raw_uid)
assert row.creator_hash != raw_uid
assert row.nickname == mask_nickname(raw_nick)
@@ -348,7 +348,7 @@ def test_douyin_store_end_to_end_sqlite(monkeypatch):
ds.DouyinStoreFactory.create_store = orig_c
captured_comment = fake_c.comments[0]
comment_obj = DouyinAwemeComment(**captured_comment) # 不抛异常即对得上
assert int(comment_obj.comment_id) == int(comment["cid"])
assert comment_obj.comment_id == comment["cid"]
assert comment_obj.creator_hash == anonymize_user_id(comment["user"]["uid"])
assert comment_obj.nickname == mask_nickname(comment["user"]["nickname"])
_assert_no_forbidden(captured_comment, "douyin_comment_orm_construct")