package schema import ( "time" "entgo.io/contrib/entproto" "entgo.io/ent" "entgo.io/ent/schema" "entgo.io/ent/schema/field" "github.com/google/uuid" ) // User holds the schema definition for the User entity. type User struct { ent.Schema } // Fields of the User. func (User) Fields() []ent.Field { return []ent.Field{ field.String("id").Unique().DefaultFunc(func() string { // 生成12位UUid 作为用户ID return uuid.New().String()[:12] }).Annotations(entproto.Field(1)), field.String("name").NotEmpty().Comment("用户名").Annotations(entproto.Field(2)), field.String("nickname").Unique().Comment("昵称").Annotations(entproto.Field(3)), field.String("email").NotEmpty().Unique().Comment("邮箱").Annotations(entproto.Field(4)), field.String("phone").NotEmpty().Unique().Comment("手机号").Annotations(entproto.Field(5)), field.String("password").NotEmpty().Sensitive().Comment("密码").Annotations(entproto.Field(6)), field.Bool("is_deleted").Default(false).Comment("是否删除").Annotations(entproto.Field(7)), field.Time("created_at").Default(time.Now).Immutable().Comment("创建时间").Annotations(entproto.Field(8)), field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间").Annotations(entproto.Field(9)), field.Time("deleted_at").Optional().Comment("删除时间").Annotations(entproto.Field(10)), } } // Edges of the User. func (User) Edges() []ent.Edge { return nil } func (User) Annotations() []schema.Annotation { return []schema.Annotation{ entproto.Message(), entproto.Service(), } }