child.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package schema
  2. import (
  3. "entgo.io/ent"
  4. "entgo.io/ent/dialect/entsql"
  5. "entgo.io/ent/schema"
  6. "entgo.io/ent/schema/edge"
  7. "entgo.io/ent/schema/field"
  8. "entgo.io/ent/schema/index"
  9. "github.com/google/uuid"
  10. "sikey/w303a/http/internal/data/schematype"
  11. )
  12. type Child struct {
  13. ent.Schema
  14. }
  15. func (Child) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.UUID("id", uuid.UUID{}).
  18. Default(uuid.New).
  19. SchemaType(schematype.UUID()).
  20. Unique().
  21. Comment("孩子ID"),
  22. field.String("child_name").
  23. MaxLen(125).
  24. SchemaType(schematype.String(125)).
  25. Comment("名字"),
  26. field.String("phone_number").
  27. MaxLen(125).
  28. NotEmpty().
  29. SchemaType(schematype.String(125)).
  30. Comment("手机号码"),
  31. field.String("area_code").
  32. Default("86").
  33. MaxLen(10).
  34. NotEmpty().
  35. SchemaType(schematype.String(10)).
  36. Comment("国际码"),
  37. field.String("avatar").
  38. MaxLen(512).
  39. Optional().
  40. Nillable().
  41. Comment("头像地址"),
  42. field.Int8("gender").
  43. Default(0).
  44. Max(3).
  45. Min(2).
  46. Comment("性别 2: 男 3: 女"),
  47. field.Int32("height").
  48. Default(120).
  49. Positive().
  50. Comment("身高 单位: cm"),
  51. field.Int32("weight").
  52. Default(100).
  53. Positive().
  54. Comment("体重 单位:g"),
  55. field.String("birthday").
  56. MaxLen(32).
  57. Optional().
  58. Nillable().
  59. Comment("生日"),
  60. field.Bool("is_enable_block_unknown_call").
  61. Default(true).
  62. Comment("是否拒接陌生人"),
  63. field.Bool("is_enable_fence").
  64. Default(false).
  65. Comment("是否开启围栏"),
  66. }
  67. }
  68. // Annotations of the Child.
  69. func (Child) Annotations() []schema.Annotation {
  70. return []schema.Annotation{
  71. entsql.Annotation{Table: "tb_child"},
  72. }
  73. }
  74. // Mixin of the Child.
  75. func (Child) Mixin() []ent.Mixin {
  76. return []ent.Mixin{
  77. TimeMixin{},
  78. }
  79. }
  80. // Edges of the Child.
  81. func (Child) Edges() []ent.Edge {
  82. return []ent.Edge{
  83. edge.To("childRefs", ChildRef.Type),
  84. edge.To("childDevice", DeviceBind.Type),
  85. edge.To("childContacts", Contacts.Type),
  86. }
  87. }
  88. // Indexes of the Child.
  89. func (Child) Indexes() []ent.Index {
  90. return []ent.Index{
  91. index.Fields("id").Unique(),
  92. }
  93. }