mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
- 迁移 226:provider CHECK 扩到 8 平台(monitors + request_templates)、 channel_monitors 加 check_mode/account_id(FK ON DELETE SET NULL)、 channel_monitor_histories 加 quota JSONB、插入公开设置 channel_monitor_show_quota(默认 false) - ent schema 同步:provider 枚举 +4、endpoint 去 NotEmpty(quota 模式存空串)、 新增 check_mode/account_id 字段、history 加 quota JSON 快照 - domain 新增归一化配额快照类型 MonitorQuotaSnapshot/Tier/Balance (放 domain 是因为 ent schema 需要引用,service 会造成 import cycle)
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package schema
|
||
|
||
import (
|
||
"time"
|
||
|
||
"github.com/Wei-Shaw/sub2api/internal/domain"
|
||
|
||
"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"
|
||
)
|
||
|
||
// ChannelMonitorHistory holds the schema definition for the ChannelMonitorHistory entity.
|
||
// 渠道监控历史:每次检测每个模型一行记录。明细只保留 1 天,超过 1 天由每日维护任务
|
||
// 先聚合到 channel_monitor_daily_rollups,再分批物理删(不用软删除:日志类表无恢复
|
||
// 需求,软删会让行和索引只增不减,徒增磁盘和查询开销)。
|
||
type ChannelMonitorHistory struct {
|
||
ent.Schema
|
||
}
|
||
|
||
func (ChannelMonitorHistory) Annotations() []schema.Annotation {
|
||
return []schema.Annotation{
|
||
entsql.Annotation{Table: "channel_monitor_histories"},
|
||
}
|
||
}
|
||
|
||
func (ChannelMonitorHistory) Fields() []ent.Field {
|
||
return []ent.Field{
|
||
field.Int64("monitor_id"),
|
||
field.String("model").
|
||
NotEmpty().
|
||
MaxLen(200),
|
||
field.Enum("status").
|
||
Values("operational", "degraded", "failed", "error"),
|
||
field.Int("latency_ms").
|
||
Optional().
|
||
Nillable(),
|
||
field.Int("ping_latency_ms").
|
||
Optional().
|
||
Nillable(),
|
||
field.String("message").
|
||
Optional().
|
||
Default("").
|
||
MaxLen(500),
|
||
// quota: 配额模式(check_mode = quota / quota_probe)检测时附带的
|
||
// 归一化配额快照(domain.MonitorQuotaSnapshot,JSONB);探活模式为 NULL。
|
||
field.JSON("quota", &domain.MonitorQuotaSnapshot{}).
|
||
Optional(),
|
||
field.Time("checked_at").
|
||
Default(time.Now),
|
||
}
|
||
}
|
||
|
||
func (ChannelMonitorHistory) Edges() []ent.Edge {
|
||
return []ent.Edge{
|
||
edge.From("monitor", ChannelMonitor.Type).
|
||
Ref("history").
|
||
Field("monitor_id").
|
||
Unique().
|
||
Required(),
|
||
}
|
||
}
|
||
|
||
func (ChannelMonitorHistory) Indexes() []ent.Index {
|
||
return []ent.Index{
|
||
index.Fields("monitor_id", "model", "checked_at"),
|
||
index.Fields("checked_at"),
|
||
}
|
||
}
|