server.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package schema
  2. import (
  3. "wechat-api/ent/schema/localmixin"
  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. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  11. )
  12. type Server struct {
  13. ent.Schema
  14. }
  15. func (Server) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.String("name").
  18. Annotations(entsql.WithComments(true)).
  19. Comment("名称"),
  20. field.String("public_ip").
  21. Annotations(entsql.WithComments(true)).
  22. Comment("公网ip"),
  23. field.String("private_ip").
  24. Annotations(entsql.WithComments(true)).
  25. Comment("内网ip"),
  26. field.String("admin_port").
  27. Annotations(entsql.WithComments(true)).
  28. Comment("管理端口")}
  29. }
  30. func (Server) Mixin() []ent.Mixin {
  31. return []ent.Mixin{
  32. mixins.IDMixin{},
  33. mixins.StatusMixin{},
  34. localmixin.SoftDeleteMixin{},
  35. }
  36. }
  37. func (Server) Indexes() []ent.Index {
  38. return []ent.Index{
  39. index.Fields("name"),
  40. index.Fields("private_ip"),
  41. index.Fields("public_ip").Unique(),
  42. }
  43. }
  44. func (Server) Edges() []ent.Edge {
  45. return []ent.Edge{
  46. edge.To("wxs", Wx.Type),
  47. }
  48. }
  49. func (Server) Annotations() []schema.Annotation {
  50. return []schema.Annotation{
  51. entsql.WithComments(true),
  52. entsql.Annotation{Table: "server"},
  53. }
  54. }