-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
86 lines (74 loc) · 3.76 KB
/
Copy pathmodel.go
File metadata and controls
86 lines (74 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package lp
import (
"strings"
"time"
"github.com/lib/pq"
"gorm.io/datatypes"
)
type Group struct {
Name string `gorm:"primaryKey;type:varchar(64);comment:组名"`
DisplayName string `gorm:"type:varchar(128);comment:显示名称"`
Weight int `gorm:"default:0;comment:权重,用于权限优先级计算"`
CreatedAt time.Time `gorm:"<-:create" json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
// 关联 - 不参与自动迁移
Users []GroupUser `gorm:"-"`
}
type GroupUser struct {
ID uint `gorm:"primarykey;AUTO_INCREMENT" json:"id,omitempty"`
UID string `gorm:"type:varchar(36);index:idx_group_user" json:"uid"`
GroupName string `gorm:"type:varchar(64);index:idx_group_user" json:"group_name"`
Expiry *time.Time `gorm:"index;comment:过期时间,NULL表示永久"`
CreatedAt time.Time `gorm:"<-:create" json:"created_at,omitempty"`
}
type Node struct {
ID uint `gorm:"primarykey;AUTO_INCREMENT" json:"id,omitempty"`
OwnerID string `gorm:"type:varchar(64);index:idx_owner;comment:所有者ID"`
OwnerType string `gorm:"type:varchar(20);index:idx_owner;comment:所有者类型"`
SubNode
CreatedAt time.Time `gorm:"<-:create" json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
type Context struct {
Key string `json:"key"`
Value string `json:"value"`
}
type SubNode struct {
Permission pq.StringArray `gorm:"type:text[];not null;index;comment:权限节点"`
Value bool `gorm:"comment:权限值"`
Weight int `gorm:"default:0;comment:权重,用于权限优先级计算"`
Expiry *time.Time `gorm:"index;comment:过期时间,NULL表示永久"`
Context datatypes.JSONType[[]Context] `json:"context,omitempty"`
}
func (m *SubNode) ToString() string {
return strings.Join(m.Permission, ".")
}
type Track struct {
Name string `gorm:"primaryKey;type:varchar(64);comment:轨道名称"`
Groups pq.StringArray `gorm:"type:[]text;comment:组名列表"`
CreatedAt time.Time `gorm:"<-:create" json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
type Meta struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:元数据ID"`
OwnerID string `gorm:"type:varchar(64);index:idx_meta_owner;comment:所有者ID"`
OwnerType string `gorm:"type:varchar(20);index:idx_meta_owner;comment:所有者类型"`
Key string `gorm:"type:varchar(100);not null;index;comment:键"`
Value string `gorm:"type:text;comment:值"`
Priority int `gorm:"default:0;comment:优先级"`
Context datatypes.JSONType[[]Context] `json:"context,omitempty"`
Expiry *time.Time `gorm:"index;comment:过期时间"`
CreatedAt time.Time `gorm:"autoCreateTime;comment:创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime;comment:更新时间"`
}
type Action struct {
ID uint `gorm:"primaryKey;autoIncrement;comment:操作ID"`
Time time.Time `gorm:"index;not null;comment:操作时间"`
ActorUUID string `gorm:"type:varchar(36);index;comment:操作者UID"`
ActorName string `gorm:"type:varchar(16);comment:操作者名称"`
Type string `gorm:"type:varchar(20);not null;comment:操作类型"`
ActedUUID string `gorm:"type:varchar(36);index;comment:被操作者UID"`
ActedName string `gorm:"type:varchar(64);comment:被操作者名称"`
Action string `gorm:"type:varchar(50);not null;comment:具体操作"`
Description string `gorm:"type:text;comment:操作描述"`
}