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:
23
backend/go-service/app/im/model/conversation.go
Normal file
23
backend/go-service/app/im/model/conversation.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// Package model 定义 IM 模块的数据库模型
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Conversation 会话模型,对应 im_conversations 表
|
||||
// Type: 1=单聊(预留 2=群聊)
|
||||
type Conversation struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` // 会话唯一标识,自增主键
|
||||
Type int `json:"type" gorm:"not null;default:1"` // 会话类型:1=单聊,2=群聊(预留)
|
||||
CreatorID int64 `json:"creator_id" gorm:"not null"` // 会话创建者用户 ID
|
||||
LastMessageID *int64 `json:"last_message_id"` // 最后一条消息 ID,用于快速定位
|
||||
LastMsgContent string `json:"last_msg_content" gorm:"type:text;default:''"` // 最后消息预览文本,用于会话列表展示
|
||||
LastMsgTime *time.Time `json:"last_msg_time" gorm:"type:timestamp(0)"` // 最后消息时间,用于排序
|
||||
LastMsgSenderID *int64 `json:"last_msg_sender_id"` // 最后消息发送者 ID
|
||||
CreatedAt time.Time `json:"created_at" gorm:"not null;autoCreateTime;type:timestamp(0)"` // 会话创建时间
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"not null;autoUpdateTime;type:timestamp(0)"` // 会话更新时间
|
||||
}
|
||||
|
||||
// TableName 指定数据库表名
|
||||
func (Conversation) TableName() string {
|
||||
return "im_conversations"
|
||||
}
|
||||
Reference in New Issue
Block a user