github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/schema/alert.go (about) 1 package schema 2 3 import ( 4 "entgo.io/ent" 5 "entgo.io/ent/dialect/entsql" 6 "entgo.io/ent/schema/edge" 7 "entgo.io/ent/schema/field" 8 "entgo.io/ent/schema/index" 9 "github.com/crowdsecurity/crowdsec/pkg/types" 10 ) 11 12 // Alert holds the schema definition for the Alert entity. 13 type Alert struct { 14 ent.Schema 15 } 16 17 // Fields of the Alert. 18 func (Alert) Fields() []ent.Field { 19 return []ent.Field{ 20 field.Time("created_at"). 21 Default(types.UtcNow). 22 UpdateDefault(types.UtcNow).Nillable().Optional(), 23 field.Time("updated_at"). 24 Default(types.UtcNow). 25 UpdateDefault(types.UtcNow).Nillable().Optional(), 26 field.String("scenario"), 27 field.String("bucketId").Default("").Optional(), 28 field.String("message").Default("").Optional(), 29 field.Int32("eventsCount").Default(0).Optional(), 30 field.Time("startedAt").Default(types.UtcNow).Optional(), 31 field.Time("stoppedAt").Default(types.UtcNow).Optional(), 32 field.String("sourceIp"). 33 Optional(), 34 field.String("sourceRange"). 35 Optional(), 36 field.String("sourceAsNumber"). 37 Optional(), 38 field.String("sourceAsName"). 39 Optional(), 40 field.String("sourceCountry"). 41 Optional(), 42 field.Float32("sourceLatitude"). 43 Optional(), 44 field.Float32("sourceLongitude"). 45 Optional(), 46 field.String("sourceScope").Optional(), 47 field.String("sourceValue").Optional(), 48 field.Int32("capacity").Optional(), 49 field.String("leakSpeed").Optional(), 50 field.String("scenarioVersion").Optional(), 51 field.String("scenarioHash").Optional(), 52 field.Bool("simulated").Default(false), 53 field.String("uuid").Optional(), //this uuid is mostly here to ensure that CAPI/PAPI has a unique id for each alert 54 } 55 } 56 57 // Edges of the Alert. 58 func (Alert) Edges() []ent.Edge { 59 return []ent.Edge{ 60 edge.From("owner", Machine.Type). 61 Ref("alerts"). 62 Unique(), 63 edge.To("decisions", Decision.Type). 64 Annotations(entsql.Annotation{ 65 OnDelete: entsql.Cascade, 66 }), 67 edge.To("events", Event.Type). 68 Annotations(entsql.Annotation{ 69 OnDelete: entsql.Cascade, 70 }), 71 edge.To("metas", Meta.Type). 72 Annotations(entsql.Annotation{ 73 OnDelete: entsql.Cascade, 74 }), 75 } 76 } 77 78 func (Alert) Indexes() []ent.Index { 79 return []ent.Index{ 80 index.Fields("id"), 81 } 82 }