package schema import ( "time" "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" ) // RequestCaptureLog 记录指定 API Key 的请求体,用于审计和分析。 // 只追加,不支持更新/删除(同 PaymentAuditLog 模式)。 type RequestCaptureLog struct { ent.Schema } func (RequestCaptureLog) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.Annotation{Table: "request_capture_logs"}, } } func (RequestCaptureLog) Fields() []ent.Field { return []ent.Field{ field.Int64("api_key_id"), field.Int64("user_id"), field.String("request_id"). MaxLen(64). Optional(). Nillable(), field.String("path"). MaxLen(100). Optional(). Nillable(), field.String("method"). MaxLen(10). Optional(). Nillable(), field.String("ip_address"). MaxLen(45). Optional(). Nillable(), // request_body 存原始 JSON 文本,不加索引,避免影响查询计划 field.Text("request_body"). Optional(). Nillable(), // response_body 存响应文本(非 streaming 为完整 JSON,streaming 为拼接的 assistant text) field.Text("response_body"). Optional(). Nillable(), // nfs_file_path NFS 文件路径快照,方便核查 field.String("nfs_file_path"). MaxLen(500). Optional(). Nillable(), field.Time("created_at"). Default(time.Now). Immutable(). SchemaType(map[string]string{dialect.Postgres: "timestamptz"}), } } func (RequestCaptureLog) Edges() []ent.Edge { return nil } func (RequestCaptureLog) Indexes() []ent.Index { return []ent.Index{ index.Fields("api_key_id", "created_at"), index.Fields("user_id"), } }