增加自动迁移数据表代码

This commit is contained in:
RockYang
2025-04-29 22:55:30 +08:00
parent d1c9fd6eba
commit 8a2d2f66b5
89 changed files with 484 additions and 406 deletions

View File

@@ -1,14 +1,21 @@
package model
import "gorm.io/gorm"
import (
"time"
)
type ChatItem struct {
BaseModel
ChatId string `gorm:"column:chat_id;unique"` // 会话 ID
UserId uint // 用户 ID
RoleId uint // 角色 ID
ModelId uint // 模型 ID
Model string // 模型
Title string // 会话标题
DeletedAt gorm.DeletedAt
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
ChatId string `gorm:"column:chat_id;type:char(40);uniqueIndex;not null;comment:会话 ID" json:"chat_id"`
UserId uint `gorm:"column:user_id;type:int;not null;comment:用户 ID" json:"user_id"`
RoleId uint `gorm:"column:role_id;type:int;not null;comment:角色 ID" json:"role_id"`
Title string `gorm:"column:title;type:varchar(100);not null;comment:会话标题" json:"title"`
ModelId uint `gorm:"column:model_id;type:int;not null;default:0;comment:模型 ID" json:"model_id"`
Model string `gorm:"column:model;type:varchar(30);comment:模型名称" json:"model"`
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;comment:更新时间" json:"updated_at"`
}
func (m *ChatItem) TableName() string {
return "chatgpt_chat_items"
}