# 数据结构 库是 SQLite(WAL 模式)。完整 DDL 见 `tieba_archiver/schema.sql`; 旧库通过 `db.ensure_compat()` 只做 `ALTER TABLE ADD COLUMN` + `CREATE TABLE IF NOT EXISTS` 升级, 不重建表。 ## 表 ### 抓取类 | 表 | 主键 | 说明 | |---|---|---| | `forum` | `fid` | 吧信息(名称、关注数、帖数) | | `thread` | `tid` | 主题:标题、作者、`reply_num`、是否精品/置顶、抓取状态、`deleted_at` | | `post` | `pid` | 楼层:`floor`、作者、纯文本 `content`、fragment JSON `frags`、赞踩、`sign`、`status`、`content_hash` | | `comment` | `cid` | 楼中楼:`pid` 所属楼层、`rto`(协议给的回复对象 uid)、`reply_to_name` / `reply_to_uid`(正文解析)、`floor` | | `user` | `uid` | 作者资料:portrait、吧等级、成长等级、性别、IP、吧务/会员 | | `image` | `url` | 图片队列:md5、体积、本地路径、下载状态 | ### 事件与状态 | 表 | 主键 | 说明 | |---|---|---| | `event` | `id` | 不可变事件:`batch`、`ts`、`kind`、`tid/pid/cid/floor`、`payload`、`source`、`evidence` | | `batch` | `id` | 每次 update / verify / restore 的批次,可整批追溯 | | `thread_seen` | `tid` | 增量快照:上次看到的 `reply_num`、`max_floor`、`seen_at` | | `post_stat_history` | `(pid, ts)` | 点赞变化点(只记变化,永久保留) | | `verify_suspect` | `(tid, pid)` | 第一次发现缺楼,等第二轮确认 | | `comment_suspect` | `cid` | 同上,楼中楼专用 | | `thread_suspect` | `tid` | 整帖 4xx 的第一次怀疑 | ### 视图 ```sql post_live -- status='live' post_recycled -- status='recycled' comment_live comment_recycled ``` 查询默认用 `_live` 视图;回收站内容用 `_recycled`。 ## 事件类型 | kind | payload | 物化效果 | |---|---|---| | `post_add` | 完整楼层行 | upsert(`status='live'`) | | `comment_add` | 完整楼中楼行(含 `reply_to_name`) | upsert | | `post_del` | 无(`evidence` 记 `missing_hits`) | `status='recycled'`,`recycle_reason='post_deleted'` | | `post_edit` | 新 `content/frags/imgs/content_hash` + 旧值 `old_*` | 更新正文 | | `thread_deleted` | 无 | `thread.deleted_at` + 该帖所有 live 楼 → `recycled`(`thread_deleted`) | | `thread_restored` | 无 | 清 `deleted_at`;只把 `thread_deleted` 的楼翻回 live | | `post_restored` | 无 | 单层翻回 live | | `comment_del` | 无 | 楼中楼 → `recycled` | | `comment_restored` | 无 | 楼中楼翻回 live | 事件同时写入: - `event` 表(可查询、可重放) - `events/<批次>.jsonl`(可搬走、可 diff、可离线备份) ## 状态机 ``` post.status: live ──(post_del)──→ recycled ←─(post_restored / thread_restored)─ comment.status: 同上 thread.deleted_at: NULL ──(thread_deleted)──→ 时间戳 ←─(thread_restored)── NULL ``` `recycle_reason`: - `post_deleted`:这一层单独被删; - `thread_deleted`:跟着整帖一起进回收站——恢复整帖时只翻回这一类。 ## 列序约定 `post` / `comment` 的历史列在前,v2 补齐列追加在表尾,回收站列再追加在最后。 旧代码如果有 `INSERT INTO post VALUES(...)` 不带列名的写法,列序一致才不会错位。 新代码一律写列名。 ## 体积参考(东方年代记吧,2026-11) | 表 | 行数 | |---|---| | thread | 30,486 | | post | 422,208 | | comment | 434,311 | | image | 88,679 | | user | 6,292 | 库 413 MB;图片 62,187 个文件 / 13.6 GiB。