| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package schema
- import (
- "github.com/Wei-Shaw/sub2api/ent/schema/mixins"
- "entgo.io/ent"
- "entgo.io/ent/dialect/entsql"
- "entgo.io/ent/schema"
- "entgo.io/ent/schema/edge"
- "entgo.io/ent/schema/field"
- "entgo.io/ent/schema/index"
- )
- // Proxy holds the schema definition for the Proxy entity.
- type Proxy struct {
- ent.Schema
- }
- func (Proxy) Annotations() []schema.Annotation {
- return []schema.Annotation{
- entsql.Annotation{Table: "proxies"},
- }
- }
- func (Proxy) Mixin() []ent.Mixin {
- return []ent.Mixin{
- mixins.TimeMixin{},
- mixins.SoftDeleteMixin{},
- }
- }
- func (Proxy) Fields() []ent.Field {
- return []ent.Field{
- field.String("name").
- MaxLen(100).
- NotEmpty(),
- field.String("protocol").
- MaxLen(20).
- NotEmpty(),
- field.String("host").
- MaxLen(255).
- NotEmpty(),
- field.Int("port"),
- field.String("username").
- MaxLen(100).
- Optional().
- Nillable(),
- field.String("password").
- MaxLen(100).
- Optional().
- Nillable(),
- field.String("status").
- MaxLen(20).
- Default("active"),
- field.Time("expires_at").
- Optional().Nillable().
- Comment("Proxy expiration time (NULL means never expires)."),
- field.String("fallback_mode").
- MaxLen(20).Default("none").
- Comment("Fallback target on expiry: none | proxy | direct."),
- field.Int64("backup_proxy_id").
- Optional().Nillable().
- Comment("Backup proxy id when fallback_mode=proxy (self-reference)."),
- field.Int("expiry_warn_days").
- Default(7).
- Comment("Days before expiry to flag as expiring-soon (per proxy)."),
- }
- }
- // Edges 定义代理实体的关联关系。
- func (Proxy) Edges() []ent.Edge {
- return []ent.Edge{
- // accounts: 使用此代理的账户(反向边)
- edge.From("accounts", Account.Type).
- Ref("proxy"),
- // Directed many-to-one: a backup can serve multiple primary proxies.
- // The inverse edge prevents Ent from treating this self-reference as symmetric.
- edge.From("primary_proxies", Proxy.Type).
- Ref("backup_proxy"),
- edge.To("backup_proxy", Proxy.Type).
- Field("backup_proxy_id").
- Unique(),
- }
- }
- func (Proxy) Indexes() []ent.Index {
- return []ent.Index{
- index.Fields("status"),
- index.Fields("deleted_at"),
- index.Fields("expires_at"),
- index.Fields("backup_proxy_id"),
- }
- }
|