初始化
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "user"},
|
||||
entsql.WithComments(true),
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
|
||||
//`name` varchar(64) NOT NULL DEFAULT '' COMMENT '姓名, 不能超过64个字符',
|
||||
// `mobile` varchar(15) NULL COMMENT '手机号',
|
||||
// `username` varchar(20) NULL COMMENT '用户名',
|
||||
// `password` varchar(60) NOT NULL DEFAULT '' COMMENT '用户密码',
|
||||
// `gender` int(1) NOT NULL DEFAULT 0 COMMENT '0:未知|1:男|2:女',
|
||||
// `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '用户头像地址',
|
||||
// `position` varchar(128) NOT NULL DEFAULT '' COMMENT '职位, 不能超过128个字符',
|
||||
// `mail` varchar(64) NOT NULL DEFAULT '' COMMENT '邮箱, 长度不超过64个字节',
|
||||
// `main_department` int(10) NOT NULL DEFAULT 0 COMMENT '主部门',
|
||||
// `status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '企业微信激活状态: 1:已激活|2:已禁用|4:未激活|5:退出企业',
|
||||
// `active` bool NOT NULL DEFAULT false COMMENT '激活',
|
||||
// `active_at` timestamp NULL COMMENT '激活时间',
|
||||
// `disabled_at` timestamp NULL COMMENT '禁用时间',
|
||||
// `last_login_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后登录IP',
|
||||
// `last_login_at` timestamp NULL COMMENT '最后登录时间',
|
||||
// `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
// `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
return []ent.Field{
|
||||
field.Int("id").Positive(),
|
||||
field.String("name").MaxLen(64).NotEmpty().Comment("姓名"),
|
||||
field.String("mobile").MaxLen(15).NotEmpty().Unique().Comment("手机号"),
|
||||
field.String("username").MaxLen(20).NotEmpty().Unique().Comment("用户名"),
|
||||
field.String("password").MaxLen(60).NotEmpty().Comment("bcrypt 哈希后的密码"),
|
||||
field.Int("roleId").Comment("Role ID"),
|
||||
field.Int("gender").Default(0).Validate(func(i int) error {
|
||||
if i != 0 && i != 1 && i != 2 {
|
||||
return fmt.Errorf("invalid gender value: %d", i)
|
||||
}
|
||||
return nil
|
||||
}).Comment("0:未知|1:男|2:女"),
|
||||
field.String("position").MaxLen(20).Optional().Comment("职位"),
|
||||
field.Int("status").Validate(func(i int) error {
|
||||
if i != 0 && i != 1 {
|
||||
return fmt.Errorf("status must be 0 or 1, got %d", i)
|
||||
}
|
||||
return nil
|
||||
}).Comment("启用状态: 1:已激活|0:已禁用"),
|
||||
field.Int("deptId").Default(1),
|
||||
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"), // 创建时间
|
||||
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间"), // 更新时间
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("role", Role.Type).
|
||||
Ref("users").
|
||||
Unique().
|
||||
Field("roleId").
|
||||
Required(),
|
||||
edge.From("dept", Department.Type).
|
||||
Ref("users").
|
||||
Unique().
|
||||
Field("deptId").
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the User.
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
// 非唯一约束索引
|
||||
index.Fields("name"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user