原来 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>
This commit is contained in:
@@ -349,10 +349,7 @@ func hashPassword(plain string) string {
|
||||
func CreateTestUser(db *gorm.DB, shopID uint64, username, password, role string) *model.User {
|
||||
hash := hashPassword(password)
|
||||
user := &model.User{
|
||||
TenantBase: model.TenantBase{
|
||||
Base: model.Base{},
|
||||
ShopID: shopID,
|
||||
},
|
||||
ShopID: shopID,
|
||||
Username: username,
|
||||
PasswordHash: hash,
|
||||
RealName: "Test User " + username,
|
||||
|
||||
Reference in New Issue
Block a user