package schema import ( "time" "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" ) // Role holds the schema definition for the Role entity. type Role struct { ent.Schema } func (Role) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.Annotation{Table: "role"}, entsql.WithComments(true), } } // Fields of the Role. func (Role) Fields() []ent.Field { return []ent.Field{ field.Int("id").Positive(), field.String("name").MaxLen(20).NotEmpty().Unique().Comment("角色名, 不能超过20个字符"), field.String("description").SchemaType( map[string]string{ dialect.MySQL: "text", dialect.Postgres: "varchar", }).MaxLen(60).Optional().Comment("描述, 不能超过60个字符"), field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"), // 创建时间 field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Comment("更新时间"), // 更新时间 } } // Edges of the Role. func (Role) Edges() []ent.Edge { return []ent.Edge{ edge.To("users", User.Type), edge.To("permissions", Permission.Type), } }