github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/schema/role.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  )
    10  
    11  // Role holds the schema definition for the Role entity.
    12  type Role struct {
    13  	ent.Schema
    14  }
    15  
    16  // Fields of the Role.
    17  func (Role) Fields() []ent.Field {
    18  	return []ent.Field{
    19  		field.String("name").Unique().StructTag(`validate:"max=255"`),
    20  		field.String("description").Optional().StructTag(`validate:"max=255"`),
    21  		field.Bool("root").Optional(),
    22  	}
    23  }
    24  
    25  // Edges of the Role.
    26  func (Role) Edges() []ent.Edge {
    27  	return []ent.Edge{
    28  		edge.To("permissions", Permission.Type).
    29  			Annotations(ondeleteCascade).
    30  			StorageKey(edge.Column("role_id"), edge.Symbol("permission_role")),
    31  		edge.To("users", User.Type).
    32  			Annotations(ondeleteSetNull),
    33  	}
    34  }
    35  
    36  func (Role) Annotations() []schema.Annotation {
    37  	return []schema.Annotation{
    38  		entsql.Annotation{
    39  			Charset:   "utf8mb4",
    40  			Collation: "utf8mb4_unicode_ci",
    41  		},
    42  	}
    43  }
    44  
    45  func (Role) Mixin() []ent.Mixin {
    46  	return []ent.Mixin{
    47  		TimeStamp{},
    48  	}
    49  }