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

     1  package schema
     2  
     3  import (
     4  	"entgo.io/ent"
     5  	"entgo.io/ent/dialect"
     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  // Decision holds the schema definition for the Decision entity.
    13  type Decision struct {
    14  	ent.Schema
    15  }
    16  
    17  // Fields of the Decision.
    18  func (Decision) 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.Time("until").Nillable().Optional().SchemaType(map[string]string{
    27  			dialect.MySQL: "datetime",
    28  		}),
    29  		field.String("scenario"),
    30  		field.String("type"),
    31  		field.Int64("start_ip").Optional(),
    32  		field.Int64("end_ip").Optional(),
    33  		field.Int64("start_suffix").Optional(),
    34  		field.Int64("end_suffix").Optional(),
    35  		field.Int64("ip_size").Optional(),
    36  		field.String("scope"),
    37  		field.String("value"),
    38  		field.String("origin"),
    39  		field.Bool("simulated").Default(false),
    40  		field.String("uuid").Optional(), //this uuid is mostly here to ensure that CAPI/PAPI has a unique id for each decision
    41  		field.Int("alert_decisions").Optional(),
    42  	}
    43  }
    44  
    45  // Edges of the Decision.
    46  func (Decision) Edges() []ent.Edge {
    47  	return []ent.Edge{
    48  		edge.From("owner", Alert.Type).
    49  			Ref("decisions").
    50  			Field("alert_decisions").
    51  			Unique(),
    52  	}
    53  }
    54  
    55  func (Decision) Indexes() []ent.Index {
    56  	return []ent.Index{
    57  		index.Fields("start_ip", "end_ip"),
    58  		index.Fields("value"),
    59  		index.Fields("until"),
    60  		index.Fields("alert_decisions"),
    61  	}
    62  }