优化平台端租户端
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SystemTenantUser struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Tid uint64 `orm:"column(tid)" json:"tid"`
|
||||
Uid uint64 `orm:"column(uid)" json:"uid"`
|
||||
GroupID uint64 `orm:"column(group_id);default(0)" json:"group_id"` // 角色ID:关联 yz_system_admin_role(id, cid=2);0=未分配(视为全权限)
|
||||
Account *string `orm:"column(account);size(64);null" json:"account"`
|
||||
Name *string `orm:"column(name);size(64);null" json:"name"`
|
||||
Phone *string `orm:"column(phone);size(20);null" json:"phone"`
|
||||
@@ -24,3 +28,19 @@ type SystemTenantUser struct {
|
||||
func (m *SystemTenantUser) TableName() string {
|
||||
return "yz_system_tenant_user"
|
||||
}
|
||||
|
||||
var tenantUserGroupColOnce sync.Once
|
||||
|
||||
// EnsureTenantUserGroupColumn 为租户用户表补齐 group_id(角色)列。
|
||||
// 历史库可能早于"用户-角色"特性建表,字段已存在时 MySQL 报 duplicate column,统一忽略。
|
||||
func EnsureTenantUserGroupColumn() {
|
||||
if Orm == nil {
|
||||
return
|
||||
}
|
||||
tenantUserGroupColOnce.Do(func() {
|
||||
_, _ = Orm.Raw(`
|
||||
ALTER TABLE yz_system_tenant_user
|
||||
ADD COLUMN group_id bigint unsigned NOT NULL DEFAULT 0 COMMENT '角色ID 关联 yz_system_admin_role(cid=2)'
|
||||
`).Exec()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user