spark-server/migrations/0015_moments.sql
2026-09-23 17:11:56 +08:00

73 lines
4.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 朋友圈。独立于 t_messages;Snowflake post_id 是主键、排序和游标。媒体在 perm/moment/,不过期,删帖时删对象。
CREATE TABLE IF NOT EXISTS t_moment_posts (
id BIGINT PRIMARY KEY COMMENT 'Snowflake 帖 id,Feed/相册游标',
user_id BIGINT NOT NULL COMMENT '作者 t_users.id',
kind SMALLINT NOT NULL COMMENT '1纯文 2图 3视频',
text VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '正文,可空;与媒体至少有一项',
content BLOB NOT NULL COMMENT '图/视频 JSON 字节,不存媒体二进制',
poi_lat DOUBLE NOT NULL DEFAULT 0 COMMENT '地点纬度,无地点为 0',
poi_lng DOUBLE NOT NULL DEFAULT 0 COMMENT '地点经度,无地点为 0',
poi_name VARCHAR(128) NOT NULL DEFAULT '' COMMENT '地点名称',
poi_address VARCHAR(256) NOT NULL DEFAULT '' COMMENT '地点地址',
visibility SMALLINT NOT NULL DEFAULT 0 COMMENT '0好友公开 1私密 2白名单 3黑名单',
status SMALLINT NOT NULL DEFAULT 0 COMMENT '0正常 1已删',
like_count INT NOT NULL DEFAULT 0 COMMENT '点赞数,与 t_moment_likes 同事务维护',
comment_count INT NOT NULL DEFAULT 0 COMMENT '未删评论数,与 t_moment_comments 同事务维护',
created_at DATETIME(3) NOT NULL COMMENT '发帖时间,visible_days 按此裁剪',
KEY idx_user_id (user_id, id)
) COMMENT='朋友圈帖。读时按好友+可见性过滤,不写每好友 inbox';
CREATE TABLE IF NOT EXISTS t_moment_audience (
post_id BIGINT NOT NULL COMMENT '帖 id',
peer_id BIGINT NOT NULL COMMENT '白名单能看 / 黑名单不能看 的好友 uid',
PRIMARY KEY (post_id, peer_id)
) COMMENT='部分可见名单。仅 visibility=2/3 有行';
CREATE TABLE IF NOT EXISTS t_moment_likes (
post_id BIGINT NOT NULL COMMENT '帖 id',
user_id BIGINT NOT NULL COMMENT '点赞人',
created_at DATETIME(3) NOT NULL COMMENT '点赞时间',
PRIMARY KEY (post_id, user_id)
) COMMENT='朋友圈点赞。重复 PUT 幂等';
CREATE TABLE IF NOT EXISTS t_moment_comments (
id BIGINT PRIMARY KEY COMMENT 'Snowflake 评论 id',
post_id BIGINT NOT NULL COMMENT '帖 id',
user_id BIGINT NOT NULL COMMENT '评论人',
reply_to_id BIGINT NOT NULL DEFAULT 0 COMMENT '父评论 id,0 表示直接评帖',
reply_to_uid BIGINT NOT NULL DEFAULT 0 COMMENT '被回复用户,0 表示直接评帖',
text VARCHAR(500) NOT NULL COMMENT '评论文本',
status SMALLINT NOT NULL DEFAULT 0 COMMENT '0正常 1已删',
created_at DATETIME(3) NOT NULL COMMENT '评论时间',
KEY idx_post (post_id, id)
) COMMENT='朋友圈评论。展示按共同好友过滤';
CREATE TABLE IF NOT EXISTS t_moment_notices (
id BIGINT PRIMARY KEY COMMENT 'Snowflake 通知 id,列表游标',
to_user_id BIGINT NOT NULL COMMENT '接收人',
from_user_id BIGINT NOT NULL COMMENT '动作发起人',
kind SMALLINT NOT NULL COMMENT '1赞 2评论 3回复',
post_id BIGINT NOT NULL COMMENT '帖 id',
comment_id BIGINT NOT NULL DEFAULT 0 COMMENT '评论 id,赞为 0',
read_at DATETIME(3) NULL COMMENT '已读时间,空表示未读',
created_at DATETIME(3) NOT NULL COMMENT '通知时间',
KEY idx_to_user (to_user_id, id)
) COMMENT='朋友圈赞评通知。不进会话 mailbox';
CREATE TABLE IF NOT EXISTS t_moment_settings (
user_id BIGINT PRIMARY KEY COMMENT '用户 t_users.id',
cover_key VARCHAR(512) NOT NULL DEFAULT '' COMMENT '封面 object_key,空表示未设',
visible_days SMALLINT NOT NULL DEFAULT 0 COMMENT '允许朋友查看范围:0全部 3/30/180 天',
last_read_post_id BIGINT NOT NULL DEFAULT 0 COMMENT '发现页红点水位,只增不减',
updated_at DATETIME(3) NOT NULL COMMENT '最近更新时间'
) COMMENT='朋友圈个人设置。无行则封面空、范围全部、水位 0';
CREATE TABLE IF NOT EXISTS t_moment_hides (
user_id BIGINT NOT NULL COMMENT '设置方',
peer_id BIGINT NOT NULL COMMENT '对方',
hide_him TINYINT NOT NULL DEFAULT 0 COMMENT '1=不看他(Feed 去掉对方)',
hide_me TINYINT NOT NULL DEFAULT 0 COMMENT '1=不让他看',
PRIMARY KEY (user_id, peer_id)
) COMMENT='不看他 / 不让他看。与拉黑分开';