github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/schema/event.go (about)

     1  package schema
     2  
     3  import (
     4  	"entgo.io/ent"
     5  	"entgo.io/ent/schema/edge"
     6  	"entgo.io/ent/schema/field"
     7  	"entgo.io/ent/schema/index"
     8  	"github.com/crowdsecurity/crowdsec/pkg/types"
     9  )
    10  
    11  // Event holds the schema definition for the Event entity.
    12  type Event struct {
    13  	ent.Schema
    14  }
    15  
    16  // Fields of the Event.
    17  func (Event) Fields() []ent.Field {
    18  	return []ent.Field{
    19  		field.Time("created_at").
    20  			Default(types.UtcNow).
    21  			UpdateDefault(types.UtcNow).Nillable().Optional(),
    22  		field.Time("updated_at").
    23  			Default(types.UtcNow).
    24  			UpdateDefault(types.UtcNow).Nillable().Optional(),
    25  		field.Time("time"),
    26  		field.String("serialized").MaxLen(8191),
    27  		field.Int("alert_events").Optional(),
    28  	}
    29  }
    30  
    31  // Edges of the Event.
    32  func (Event) Edges() []ent.Edge {
    33  	return []ent.Edge{
    34  		edge.From("owner", Alert.Type).
    35  			Ref("events").
    36  			Field("alert_events").
    37  			Unique(),
    38  	}
    39  }
    40  
    41  func (Event) Indexes() []ent.Index {
    42  	return []ent.Index{
    43  		index.Fields("alert_events"),
    44  	}
    45  }