2020-11-30 09:37:17 +00:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
2021-03-15 17:46:52 +00:00
|
|
|
"entgo.io/ent"
|
|
|
|
"entgo.io/ent/schema/edge"
|
|
|
|
"entgo.io/ent/schema/field"
|
2023-05-11 11:49:01 +00:00
|
|
|
"entgo.io/ent/schema/index"
|
2022-01-19 13:56:05 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
2020-11-30 09:37:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Event holds the schema definition for the Event entity.
|
|
|
|
type Event struct {
|
|
|
|
ent.Schema
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fields of the Event.
|
|
|
|
func (Event) Fields() []ent.Field {
|
|
|
|
return []ent.Field{
|
|
|
|
field.Time("created_at").
|
2022-01-19 13:56:05 +00:00
|
|
|
Default(types.UtcNow).
|
|
|
|
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
2020-11-30 09:37:17 +00:00
|
|
|
field.Time("updated_at").
|
2022-01-19 13:56:05 +00:00
|
|
|
Default(types.UtcNow).
|
|
|
|
UpdateDefault(types.UtcNow).Nillable().Optional(),
|
2020-11-30 09:37:17 +00:00
|
|
|
field.Time("time"),
|
2021-08-03 13:46:10 +00:00
|
|
|
field.String("serialized").MaxLen(8191),
|
2023-05-11 11:49:01 +00:00
|
|
|
field.Int("alert_events").Optional(),
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edges of the Event.
|
|
|
|
func (Event) Edges() []ent.Edge {
|
|
|
|
return []ent.Edge{
|
|
|
|
edge.From("owner", Alert.Type).
|
|
|
|
Ref("events").
|
2023-05-11 11:49:01 +00:00
|
|
|
Field("alert_events").
|
2020-11-30 09:37:17 +00:00
|
|
|
Unique(),
|
|
|
|
}
|
|
|
|
}
|
2023-05-11 11:49:01 +00:00
|
|
|
|
|
|
|
func (Event) Indexes() []ent.Index {
|
|
|
|
return []ent.Index{
|
|
|
|
index.Fields("alert_events"),
|
|
|
|
}
|
|
|
|
}
|