wood chen 31f65a9301 优化用户模型 Email 字段长度限制
- 为 Email 字段添加 varchar(191) 类型约束
- 确保数据库兼容性和索引性能
2025-03-06 23:37:14 +08:00

38 lines
1.1 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type User struct {
ID uint `json:"id" gorm:"primaryKey"`
Username string `json:"username" gorm:"not null;unique"`
Email string `json:"email" gorm:"not null;type:varchar(191)"`
Role string `json:"role" gorm:"not null;default:user"` // admin or user
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
type Session struct {
ID string `json:"id" gorm:"primaryKey"`
UserID uint `json:"user_id" gorm:"not null"`
User User `json:"user" gorm:"foreignKey:UserID"`
ExpiresAt time.Time `json:"expires_at" gorm:"not null"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// TableName 指定User表名
func (User) TableName() string {
return "user"
}
// TableName 指定Session表名
func (Session) TableName() string {
return "session"
}