github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/schema/permission.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 // Permission holds the schema definition for the Permission entity. 13 type Permission struct { 14 ent.Schema 15 } 16 17 // Fields of the Permission. 18 func (Permission) Fields() []ent.Field { 19 return []ent.Field{ 20 field.Int("role_id"), 21 field.String("action").StructTag(`validate:"max=255"`), 22 field.String("value").Comment("all | own | none"), 23 } 24 } 25 26 // Edges of the Permission. 27 func (Permission) Edges() []ent.Edge { 28 return []ent.Edge{ 29 edge.From("role", Role.Type).Ref("permissions").Unique().Field("role_id").Required(), 30 } 31 } 32 33 func (Permission) Indexes() []ent.Index { 34 return []ent.Index{ 35 index.Fields("role_id", "action").Unique().StorageKey("role_action_unique_idx"), 36 } 37 } 38 39 func (Permission) Annotations() []schema.Annotation { 40 return []schema.Annotation{ 41 entsql.Annotation{ 42 Charset: "utf8mb4", 43 Collation: "utf8mb4_unicode_ci", 44 }, 45 } 46 } 47 48 func (Permission) Mixin() []ent.Mixin { 49 return []ent.Mixin{ 50 TimeStamp{}, 51 } 52 }