Skip to content

TSID 字段真值矩阵(首版)

Last Updated: 2026-04-11
Status: Working draft
Purpose: 用一份矩阵拆开 TSID 的“生成方式、字段语义、物理类型、API 表示、客户端表示”,作为后续批次修复的单一参考。


1. 判定规则

字段角色

  • TSID primary key
    • 本表主键 id 由应用层 elib_tsid:generate/1 生成。
  • TSID foreign/semantic field
    • 字段值承载其他实体的 TSID,但不是本表内新生成。
  • Local surrogate key
    • 仅用于本地缓存表或中间表的自增主键,不代表后端实体 ID。
  • Business string key
    • 业务主键是字符串,不属于 TSID。

本矩阵当前范围

  • 优先覆盖已经确认冲突或跨端耦合最强的字段。
  • 不是最终全量字段清单,后续会继续扩充。

2. 由应用层直接生成 TSID 的主键(高置信度)

DomainTableFieldRoleGenerator NamePostgreSQL TypeNotes
UseruseridTSID primary keyuserBIGINT用户主键
Useruser_deviceidTSID primary keyuser_deviceBIGINT设备记录主键
Useruser_collectidTSID primary keyuser_collectBIGINT收藏记录主键
Useruser_denylistidTSID primary keyuser_denylistBIGINT黑名单记录主键
Useruser_tagidTSID primary keyuser_tagBIGINT标签主键
Useruser_tag_relationidTSID primary keyuser_tag_relationBIGINT标签关系主键
Frienduser_friendidTSID primary keyfriendBIGINT生成器名和表名不一致
Frienduser_friend_categoryidTSID primary keyfriend_categoryBIGINT生成器名和表名不一致
GroupgroupidTSID primary keygroup_infoBIGINT生成器名和表名不一致
Groupgroup_memberidTSID primary keygroup_memberBIGINT群成员关系主键
Groupgroup_noticeidTSID primary keygroup_noticeBIGINT公告主键
Groupgroup_logidTSID primary keygroup_logBIGINT治理日志主键
Groupgroup_random_codeidTSID primary keygroup_random_codeBIGINT入群码记录主键
Groupgroup_categoryidTSID primary keygroup_categoryBIGINT分类主键
Groupgroup_tagidTSID primary keygroup_tagBIGINT标签主键
Groupgroup_voteidTSID primary keygroup_voteBIGINT投票主键
Groupgroup_vote_optionidTSID primary keygroup_vote_optionBIGINT选项主键
Groupgroup_scheduleidTSID primary keygroup_scheduleBIGINT日程主键
Groupgroup_schedule_participantidTSID primary keygroup_scheduleBIGINT代码当前复用 group_schedule 生成器,待后续单独决策
Groupgroup_schedule_remindidTSID primary keygroup_schedule_reminderBIGINT生成器名和表名不一致
Groupgroup_albumidTSID primary keygroup_albumBIGINT相册主键
Groupgroup_album_photoidTSID primary keygroup_album_photoBIGINT图片主键
Groupgroup_album_photo_commentidTSID primary keygroup_album_commentBIGINT生成器名和表名不一致
Groupgroup_fileidTSID primary keygroup_fileBIGINT文件主键
Groupgroup_taskidTSID primary keygroup_taskBIGINT任务主键
Groupgroup_task_assignmentidTSID primary keygroup_task_assignmentBIGINT作业提交主键
Messagemsg_c2c.ididTSID primary keymsg_c2cBIGINT消息存储行主键,不等于 msg_id
Messagemsg_c2g.ididTSID primary keymsg_c2gBIGINT同上
Messagemsg_c2s.ididTSID primary keymsg_c2sBIGINT同上
Messagemsg_s2c.ididTSID primary keymsg_s2cBIGINT同上
Messagemsg_storeidTSID primary keymsg_storeBIGINT归档消息行主键
Messagemsg_readidTSID primary keymsg_readBIGINT已读回执主键
Messagemsg_mentionidTSID primary keymsg_mentionBIGINT@提醒主键
Messagemsg_forwardidTSID primary keymsg_forwardBIGINT转发记录主键
Messagemsg_reactionidTSID primary keymsg_reactionBIGINT反应主键
Conversationconversation_deleteidTSID primary keyconversation_deleteBIGINT删除标记主键
Conversationconversation_pinidTSID primary keyconversation_pinBIGINT置顶记录主键
AttachmentattachmentidTSID primary keyattachmentBIGINT附件主键
Momentmoment_postidTSID primary keymoment_postBIGINT动态主键
Momentmoment_commentidTSID primary keymoment_commentBIGINT评论主键
Momentmoment_likeidTSID primary keymoment_likeBIGINT点赞主键
Momentmoment_timelineidTSID primary keymoment_timelineBIGINT时间线行主键
Momentmoment_post_aclidTSID primary keymoment_post_aclBIGINTACL 行主键
Momentmoment_reportidTSID primary keymoment_reportBIGINT举报主键
ChannelchannelidTSID primary keychannelBIGINT频道主键
Channelchannel_messageidTSID primary keychannel_messageBIGINT频道消息主键
Channelchannel_subscriptionidTSID primary keychannel_subscriptionBIGINT订阅关系主键
Channelchannel_adminidTSID primary keychannel_adminBIGINT管理员关系主键
Channelchannel_message_viewidTSID primary keychannel_message_viewBIGINT消息阅读视图表主键
Channelchannel_orderidTSID primary keychannel_orderBIGINT订单主键
Channelchannel_invitationidTSID primary keychannel_invitationBIGINT邀请主键
FeedbackfeedbackidTSID primary keyfeedbackBIGINT反馈主键
Reportreport_ticketidTSID primary keyreport_ticketBIGINT工单主键
Reportreport_action_logidTSID primary keyreport_action_logBIGINT处理动作主键
WalletwalletidTSID primary keywalletBIGINT钱包主键
Walletwallet_transactionidTSID primary keywallet_transactionBIGINT流水主键
Livelive_roomidTSID primary keylive_roomBIGINT直播间主键
Appapp_versionidTSID primary keyapp_versionBIGINT版本主键
Appapp_ddlidTSID primary keyapp_ddlBIGINTDDL 版本记录主键
Appapp_upgrade_logidTSID primary keyapp_upgrade_logBIGINT升级日志主键
Appapp_version_policyidTSID primary keyapp_version_policyBIGINT升级策略主键

3. 承载 TSID 语义,但不是本表新生成

TableFieldRolePostgreSQL TypeCurrent API / Client Notes
msg_c2cfrom_id, to_idTSID foreign/semantic fieldBIGINT消息发送方/接收方 TSID
msg_c2gfrom_id, to_idTSID foreign/semantic fieldBIGINTto_id 语义是群 TSID
msg_c2sfrom_id, to_idTSID foreign/semantic fieldBIGINT同上
msg_s2cfrom_id, to_idTSID foreign/semantic fieldBIGINTS2C 发送方可为 0
channelcreator_uidTSID foreign/semantic fieldBIGINT管理端有时以 owner_id 暴露
channel_messagechannel_id, author_idTSID foreign/semantic fieldBIGINT管理端消息列表已 string 化
channel_subscriptionchannel_id, user_id, last_message_idTSID foreign/semantic fieldBIGINT本地 SQLite 中部分列为远端 TSID,id 不是
channel_adminchannel_id, user_idTSID foreign/semantic fieldBIGINT同上
groupowner_uid, creator_uidTSID foreign/semantic fieldBIGINT管理端已 string 化
group_membergroup_id, user_idTSID foreign/semantic fieldBIGINT管理端已 string 化
group_noticegroup_id, user_id, edit_user_idTSID foreign/semantic fieldBIGINTFlutter SQLite 已迁为 INTEGER
moment_postauthor_uidTSID foreign/semantic fieldBIGINT动态作者 TSID
moment_commentpost_id, user_id, reply_to_uidTSID foreign/semantic fieldBIGINTpost_id 是动态 TSID
moment_likepost_id, user_idTSID foreign/semantic fieldBIGINT同上
moment_timelinerecipient_uid, post_id, author_uidTSID foreign/semantic fieldBIGINT时间线归属/动态/作者
moment_reportpost_id, reporter_uid, handled_byTSID foreign/semantic fieldBIGINT举报相关 TSID
conversationuser_id, peer_id, last_msg_idTSID foreign/semantic fieldVARCHAR(40)语义已偏向 TSID,但物理类型仍是字符串
msg_c2cmsg_idTSID foreign/semantic fieldVARCHAR(40)业务消息 ID;API 和文档仍未完全统一为 string
msg_c2gmsg_idTSID foreign/semantic fieldVARCHAR(40)同上

4. 明确不是 TSID 主键的对象

TableFieldRolePostgreSQL TypeNotes
verification_codeidBusiness string keyVARCHAR(80)邮箱/手机号等业务键,不应注册 TSID 生成器
geo_people_nearbyuser_idTSID foreign/semantic fieldBIGINT主键就是用户 TSID,但不是本表独立生成的新 id
user_settinguser_idTSID foreign/semantic fieldBIGINTuser_id 为主键,不应额外写入 id
user_loguidTSID foreign/semantic fieldBIGINT日志表没有 id 列,不应注入 TSID 主键

5. Flutter / SQLite 的关键边界

SQLite TableFieldRoleSQLite TypeNotes
conversationidLocal surrogate keyINTEGER PRIMARY KEY AUTOINCREMENT本地会话行号,不等于后端会话 TSID
conversationpeer_id, last_msg_idTSID foreign/semantic fieldINTEGER远端实体 TSID
channel_subscriptionidLocal surrogate keyINTEGER PRIMARY KEY AUTOINCREMENT本地缓存主键
channel_subscriptionchannel_id, last_message_idTSID foreign/semantic fieldINTEGER远端频道/消息 TSID
channel_adminidLocal surrogate keyINTEGER PRIMARY KEY AUTOINCREMENT本地缓存主键
channel_adminchannel_id, user_idTSID foreign/semantic fieldINTEGER远端 TSID
msg_c2cid, from_id, to_idTSID foreign/semantic fieldINTEGER本地消息表直接存远端 TSID
group_noticeid, group_id, user_id, edit_user_idTSID foreign/semantic fieldINTEGER预置库 example10.db 已是 v16 结构

6. 已确认的冲突点

  1. user_log_repo 曾向 user_log 写入 id,但表无此列。
  2. user_setting_repo 曾向 user_setting 写入 id,但表无此列。
  3. imboy_app:tsid_generator_names/0 已清理以下误注册对象:
    • user_log
    • user_setting
    • verification_code
    • geo_people_nearby
  4. 文档对 JSON TSID 的描述仍未和 Admin API 现实行为对齐。
  5. elib_pg_sql 仍需要兼容导出 insert/2,否则大量 Repo 会在运行时触发 undef;这不是 TSID 语义问题,但会直接掩盖本轮修复验证。

7. 后续扩展方向

  • 补全全部 Repo 和 migration 的字段矩阵
  • 明确 App REST、Admin REST、WebSocket 三条协议边界是否统一使用 string
  • 补一份“生成器名 <-> 表名”映射清单,消除命名错位

IMBoy — 企业私有化即时通讯平台