Files
jiu/backend/internal/model/user.go
T
wangjia 86baaf3a1c
Deploy / deploy (push) Successful in 1m13s
fix(model): users 唯一索引改为 (shop_id, username) 复合索引
原来 uniqueIndex:uk_shop_username 只在 Username 字段上,导致用户名全局唯一。
S002/S003 的 admin 用户与 S001 冲突,INSERT 被静默跳过,无法登录。

将 User 的 TenantBase 改为直接定义 ShopID,使其参与复合唯一索引。
需要 Reset DB 使新索引生效。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 14:50:34 +08:00

14 lines
614 B
Go

package model
type User struct {
Base
ShopID uint64 `gorm:"not null;index;uniqueIndex:uk_shop_username" json:"shop_id"`
Username string `gorm:"size:50;uniqueIndex:uk_shop_username" json:"username"`
PasswordHash string `gorm:"size:255" json:"-"`
RealName string `gorm:"size:50" json:"real_name"`
Phone string `gorm:"size:30" json:"phone"`
Role string `gorm:"type:enum('admin','operator','readonly','superadmin');default:'operator'" json:"role"`
IsActive bool `gorm:"default:true" json:"is_active"`
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
}