feat(schema): 添加基础混入定义公共时间字段

This commit is contained in:
unclesam committed 2026-07-07 19:43:16 +08:00
1 parent 5281459fcb
commit fe86c081f4
16 files changed
+1715 -14

No files matched your search

+28 -2
View File
@@ -1,15 +1,41 @@
package schema
import "entgo.io/ent"
import (
"regexp"
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
BaseMixin{},
}
}
// Fields of the User.
func (User) Fields() []ent.Field {
return nil
return []ent.Field{
field.String("username").
Unique().
NotEmpty(),
field.String("password").
Sensitive(),
field.String("email").
Optional().
Match(regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)), // 邮箱格式正则校验
field.String("ip").
Optional().
Match(regexp.MustCompile(`^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$`)),
field.String("addr").
Optional().
MaxLen(500),
}
}
// Edges of the User.