feat(im): Task 0 - IM 模型定义 + 数据库表迁移 + 常量定义

- 新增 3 个 GORM 模型:Conversation / ConversationMember / Message
- 新增 IM 常量:会话类型、消息类型、消息状态、撤回时限
- main.go 添加 IM 表 AutoMigrate
- init.sql 追加 IM 模块 DDL(含索引和全文搜索 GIN 索引)

Made-with: Cursor
This commit is contained in:
bujinyuan
2026-03-03 10:41:42 +08:00
parent 1f390fce56
commit 6ab04fb902
6 changed files with 227 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
package model
import "time"
// Message 消息模型,对应 im_messages 表
// Type: 1=文本(预留 2=图片 3=语音 4=视频 5=文件)
// Status: 1=正常 2=已撤回 3=已删除
type Message struct {
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` // 消息唯一标识,自增主键
ConversationID int64 `json:"conversation_id" gorm:"not null;index:idx_msg_conv_time;index:idx_msg_conv_id"` // 所属会话 ID
SenderID int64 `json:"sender_id" gorm:"not null"` // 发送者用户 ID
Type int `json:"type" gorm:"not null;default:1"` // 消息类型1=文本(预留扩展)
Content string `json:"content" gorm:"type:text;not null"` // 消息内容
Extra *string `json:"extra" gorm:"type:jsonb"` // 扩展数据JSON 格式,预留图片/语音等元信息)
Status int `json:"status" gorm:"not null;default:1"` // 消息状态1=正常2=已撤回3=已删除
ClientMsgID string `json:"client_msg_id" gorm:"size:64;default:''"` // 客户端消息唯一 ID用于幂等去重
CreatedAt time.Time `json:"created_at" gorm:"not null;autoCreateTime;type:timestamp(0)"` // 消息发送时间
}
// TableName 指定数据库表名
func (Message) TableName() string {
return "im_messages"
}