github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/schema/page.go (about) 1 package schema 2 3 import ( 4 "entgo.io/ent" 5 "entgo.io/ent/dialect/entsql" 6 "entgo.io/ent/schema" 7 "entgo.io/ent/schema/edge" 8 "entgo.io/ent/schema/field" 9 "entgo.io/ent/schema/index" 10 ) 11 12 // Page holds the schema definition for the Page entity. 13 type Page struct { 14 ent.Schema 15 } 16 17 // Fields of the Page. 18 func (Page) Fields() []ent.Field { 19 return []ent.Field{ 20 field.String("name"), 21 field.String("slug"), 22 field.Text("content").StructTag(`validate:"required"`), 23 field.Text("content_html"), 24 field.Bool("draft").Optional().Default(false), 25 field.Int("featured_image_id").Optional(), 26 } 27 } 28 29 // Edges of the Page. 30 func (Page) Edges() []ent.Edge { 31 return []ent.Edge{ 32 edge.From("featured_image", File.Type).Ref("pages").Field("featured_image_id").Unique(), 33 } 34 } 35 36 func (Page) Indexes() []ent.Index { 37 return []ent.Index{ 38 index.Fields("name").StorageKey("name_idx"), 39 index.Fields("slug").StorageKey("slug_unique").Unique(), 40 } 41 } 42 43 func (Page) Annotations() []schema.Annotation { 44 return []schema.Annotation{ 45 entsql.Annotation{ 46 Charset: "utf8mb4", 47 Collation: "utf8mb4_unicode_ci", 48 }, 49 } 50 } 51 52 func (Page) Mixin() []ent.Mixin { 53 return []ent.Mixin{ 54 TimeStamp{}, 55 } 56 }