USE hyapp_user;

CREATE TABLE IF NOT EXISTS user_follow_events (
  app_code VARCHAR(32) NOT NULL DEFAULT 'lalu' COMMENT '应用编码，用于多租户隔离',
  event_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '关注状态变化事件 ID',
  follower_user_id BIGINT NOT NULL COMMENT '关注人用户 ID',
  followee_user_id BIGINT NOT NULL COMMENT '被关注人用户 ID',
  delta TINYINT NOT NULL COMMENT '关注 +1，取消关注 -1',
  occurred_at_ms BIGINT NOT NULL COMMENT '事件时间，UTC epoch ms',
  PRIMARY KEY (event_id),
  KEY idx_user_follow_events_followee_time (app_code, followee_user_id, occurred_at_ms, event_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户关注净增统计事件表';

CREATE TABLE IF NOT EXISTS user_private_message_events (
  app_code VARCHAR(32) NOT NULL DEFAULT 'lalu' COMMENT '应用编码，用于多租户隔离',
  event_id VARCHAR(128) NOT NULL COMMENT '腾讯 IM 私信事件幂等 ID',
  sender_user_id BIGINT NOT NULL COMMENT '消息发送用户 ID',
  target_user_id BIGINT NOT NULL COMMENT '消息接收用户 ID',
  occurred_at_ms BIGINT NOT NULL COMMENT '发送时间，UTC epoch ms',
  created_at_ms BIGINT NOT NULL COMMENT '落库时间，UTC epoch ms',
  PRIMARY KEY (app_code, event_id),
  KEY idx_private_message_target_time (app_code, target_user_id, occurred_at_ms, sender_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户私信发送事实，仅保存统计字段';
