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

     1  // Code generated by ent, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"time"
    10  
    11  	"entgo.io/ent/dialect/sql"
    12  	"entgo.io/ent/dialect/sql/sqlgraph"
    13  	"entgo.io/ent/schema/field"
    14  	"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
    15  	"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
    16  	"github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate"
    17  )
    18  
    19  // DecisionUpdate is the builder for updating Decision entities.
    20  type DecisionUpdate struct {
    21  	config
    22  	hooks    []Hook
    23  	mutation *DecisionMutation
    24  }
    25  
    26  // Where appends a list predicates to the DecisionUpdate builder.
    27  func (du *DecisionUpdate) Where(ps ...predicate.Decision) *DecisionUpdate {
    28  	du.mutation.Where(ps...)
    29  	return du
    30  }
    31  
    32  // SetCreatedAt sets the "created_at" field.
    33  func (du *DecisionUpdate) SetCreatedAt(t time.Time) *DecisionUpdate {
    34  	du.mutation.SetCreatedAt(t)
    35  	return du
    36  }
    37  
    38  // ClearCreatedAt clears the value of the "created_at" field.
    39  func (du *DecisionUpdate) ClearCreatedAt() *DecisionUpdate {
    40  	du.mutation.ClearCreatedAt()
    41  	return du
    42  }
    43  
    44  // SetUpdatedAt sets the "updated_at" field.
    45  func (du *DecisionUpdate) SetUpdatedAt(t time.Time) *DecisionUpdate {
    46  	du.mutation.SetUpdatedAt(t)
    47  	return du
    48  }
    49  
    50  // ClearUpdatedAt clears the value of the "updated_at" field.
    51  func (du *DecisionUpdate) ClearUpdatedAt() *DecisionUpdate {
    52  	du.mutation.ClearUpdatedAt()
    53  	return du
    54  }
    55  
    56  // SetUntil sets the "until" field.
    57  func (du *DecisionUpdate) SetUntil(t time.Time) *DecisionUpdate {
    58  	du.mutation.SetUntil(t)
    59  	return du
    60  }
    61  
    62  // SetNillableUntil sets the "until" field if the given value is not nil.
    63  func (du *DecisionUpdate) SetNillableUntil(t *time.Time) *DecisionUpdate {
    64  	if t != nil {
    65  		du.SetUntil(*t)
    66  	}
    67  	return du
    68  }
    69  
    70  // ClearUntil clears the value of the "until" field.
    71  func (du *DecisionUpdate) ClearUntil() *DecisionUpdate {
    72  	du.mutation.ClearUntil()
    73  	return du
    74  }
    75  
    76  // SetScenario sets the "scenario" field.
    77  func (du *DecisionUpdate) SetScenario(s string) *DecisionUpdate {
    78  	du.mutation.SetScenario(s)
    79  	return du
    80  }
    81  
    82  // SetNillableScenario sets the "scenario" field if the given value is not nil.
    83  func (du *DecisionUpdate) SetNillableScenario(s *string) *DecisionUpdate {
    84  	if s != nil {
    85  		du.SetScenario(*s)
    86  	}
    87  	return du
    88  }
    89  
    90  // SetType sets the "type" field.
    91  func (du *DecisionUpdate) SetType(s string) *DecisionUpdate {
    92  	du.mutation.SetType(s)
    93  	return du
    94  }
    95  
    96  // SetNillableType sets the "type" field if the given value is not nil.
    97  func (du *DecisionUpdate) SetNillableType(s *string) *DecisionUpdate {
    98  	if s != nil {
    99  		du.SetType(*s)
   100  	}
   101  	return du
   102  }
   103  
   104  // SetStartIP sets the "start_ip" field.
   105  func (du *DecisionUpdate) SetStartIP(i int64) *DecisionUpdate {
   106  	du.mutation.ResetStartIP()
   107  	du.mutation.SetStartIP(i)
   108  	return du
   109  }
   110  
   111  // SetNillableStartIP sets the "start_ip" field if the given value is not nil.
   112  func (du *DecisionUpdate) SetNillableStartIP(i *int64) *DecisionUpdate {
   113  	if i != nil {
   114  		du.SetStartIP(*i)
   115  	}
   116  	return du
   117  }
   118  
   119  // AddStartIP adds i to the "start_ip" field.
   120  func (du *DecisionUpdate) AddStartIP(i int64) *DecisionUpdate {
   121  	du.mutation.AddStartIP(i)
   122  	return du
   123  }
   124  
   125  // ClearStartIP clears the value of the "start_ip" field.
   126  func (du *DecisionUpdate) ClearStartIP() *DecisionUpdate {
   127  	du.mutation.ClearStartIP()
   128  	return du
   129  }
   130  
   131  // SetEndIP sets the "end_ip" field.
   132  func (du *DecisionUpdate) SetEndIP(i int64) *DecisionUpdate {
   133  	du.mutation.ResetEndIP()
   134  	du.mutation.SetEndIP(i)
   135  	return du
   136  }
   137  
   138  // SetNillableEndIP sets the "end_ip" field if the given value is not nil.
   139  func (du *DecisionUpdate) SetNillableEndIP(i *int64) *DecisionUpdate {
   140  	if i != nil {
   141  		du.SetEndIP(*i)
   142  	}
   143  	return du
   144  }
   145  
   146  // AddEndIP adds i to the "end_ip" field.
   147  func (du *DecisionUpdate) AddEndIP(i int64) *DecisionUpdate {
   148  	du.mutation.AddEndIP(i)
   149  	return du
   150  }
   151  
   152  // ClearEndIP clears the value of the "end_ip" field.
   153  func (du *DecisionUpdate) ClearEndIP() *DecisionUpdate {
   154  	du.mutation.ClearEndIP()
   155  	return du
   156  }
   157  
   158  // SetStartSuffix sets the "start_suffix" field.
   159  func (du *DecisionUpdate) SetStartSuffix(i int64) *DecisionUpdate {
   160  	du.mutation.ResetStartSuffix()
   161  	du.mutation.SetStartSuffix(i)
   162  	return du
   163  }
   164  
   165  // SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil.
   166  func (du *DecisionUpdate) SetNillableStartSuffix(i *int64) *DecisionUpdate {
   167  	if i != nil {
   168  		du.SetStartSuffix(*i)
   169  	}
   170  	return du
   171  }
   172  
   173  // AddStartSuffix adds i to the "start_suffix" field.
   174  func (du *DecisionUpdate) AddStartSuffix(i int64) *DecisionUpdate {
   175  	du.mutation.AddStartSuffix(i)
   176  	return du
   177  }
   178  
   179  // ClearStartSuffix clears the value of the "start_suffix" field.
   180  func (du *DecisionUpdate) ClearStartSuffix() *DecisionUpdate {
   181  	du.mutation.ClearStartSuffix()
   182  	return du
   183  }
   184  
   185  // SetEndSuffix sets the "end_suffix" field.
   186  func (du *DecisionUpdate) SetEndSuffix(i int64) *DecisionUpdate {
   187  	du.mutation.ResetEndSuffix()
   188  	du.mutation.SetEndSuffix(i)
   189  	return du
   190  }
   191  
   192  // SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil.
   193  func (du *DecisionUpdate) SetNillableEndSuffix(i *int64) *DecisionUpdate {
   194  	if i != nil {
   195  		du.SetEndSuffix(*i)
   196  	}
   197  	return du
   198  }
   199  
   200  // AddEndSuffix adds i to the "end_suffix" field.
   201  func (du *DecisionUpdate) AddEndSuffix(i int64) *DecisionUpdate {
   202  	du.mutation.AddEndSuffix(i)
   203  	return du
   204  }
   205  
   206  // ClearEndSuffix clears the value of the "end_suffix" field.
   207  func (du *DecisionUpdate) ClearEndSuffix() *DecisionUpdate {
   208  	du.mutation.ClearEndSuffix()
   209  	return du
   210  }
   211  
   212  // SetIPSize sets the "ip_size" field.
   213  func (du *DecisionUpdate) SetIPSize(i int64) *DecisionUpdate {
   214  	du.mutation.ResetIPSize()
   215  	du.mutation.SetIPSize(i)
   216  	return du
   217  }
   218  
   219  // SetNillableIPSize sets the "ip_size" field if the given value is not nil.
   220  func (du *DecisionUpdate) SetNillableIPSize(i *int64) *DecisionUpdate {
   221  	if i != nil {
   222  		du.SetIPSize(*i)
   223  	}
   224  	return du
   225  }
   226  
   227  // AddIPSize adds i to the "ip_size" field.
   228  func (du *DecisionUpdate) AddIPSize(i int64) *DecisionUpdate {
   229  	du.mutation.AddIPSize(i)
   230  	return du
   231  }
   232  
   233  // ClearIPSize clears the value of the "ip_size" field.
   234  func (du *DecisionUpdate) ClearIPSize() *DecisionUpdate {
   235  	du.mutation.ClearIPSize()
   236  	return du
   237  }
   238  
   239  // SetScope sets the "scope" field.
   240  func (du *DecisionUpdate) SetScope(s string) *DecisionUpdate {
   241  	du.mutation.SetScope(s)
   242  	return du
   243  }
   244  
   245  // SetNillableScope sets the "scope" field if the given value is not nil.
   246  func (du *DecisionUpdate) SetNillableScope(s *string) *DecisionUpdate {
   247  	if s != nil {
   248  		du.SetScope(*s)
   249  	}
   250  	return du
   251  }
   252  
   253  // SetValue sets the "value" field.
   254  func (du *DecisionUpdate) SetValue(s string) *DecisionUpdate {
   255  	du.mutation.SetValue(s)
   256  	return du
   257  }
   258  
   259  // SetNillableValue sets the "value" field if the given value is not nil.
   260  func (du *DecisionUpdate) SetNillableValue(s *string) *DecisionUpdate {
   261  	if s != nil {
   262  		du.SetValue(*s)
   263  	}
   264  	return du
   265  }
   266  
   267  // SetOrigin sets the "origin" field.
   268  func (du *DecisionUpdate) SetOrigin(s string) *DecisionUpdate {
   269  	du.mutation.SetOrigin(s)
   270  	return du
   271  }
   272  
   273  // SetNillableOrigin sets the "origin" field if the given value is not nil.
   274  func (du *DecisionUpdate) SetNillableOrigin(s *string) *DecisionUpdate {
   275  	if s != nil {
   276  		du.SetOrigin(*s)
   277  	}
   278  	return du
   279  }
   280  
   281  // SetSimulated sets the "simulated" field.
   282  func (du *DecisionUpdate) SetSimulated(b bool) *DecisionUpdate {
   283  	du.mutation.SetSimulated(b)
   284  	return du
   285  }
   286  
   287  // SetNillableSimulated sets the "simulated" field if the given value is not nil.
   288  func (du *DecisionUpdate) SetNillableSimulated(b *bool) *DecisionUpdate {
   289  	if b != nil {
   290  		du.SetSimulated(*b)
   291  	}
   292  	return du
   293  }
   294  
   295  // SetUUID sets the "uuid" field.
   296  func (du *DecisionUpdate) SetUUID(s string) *DecisionUpdate {
   297  	du.mutation.SetUUID(s)
   298  	return du
   299  }
   300  
   301  // SetNillableUUID sets the "uuid" field if the given value is not nil.
   302  func (du *DecisionUpdate) SetNillableUUID(s *string) *DecisionUpdate {
   303  	if s != nil {
   304  		du.SetUUID(*s)
   305  	}
   306  	return du
   307  }
   308  
   309  // ClearUUID clears the value of the "uuid" field.
   310  func (du *DecisionUpdate) ClearUUID() *DecisionUpdate {
   311  	du.mutation.ClearUUID()
   312  	return du
   313  }
   314  
   315  // SetAlertDecisions sets the "alert_decisions" field.
   316  func (du *DecisionUpdate) SetAlertDecisions(i int) *DecisionUpdate {
   317  	du.mutation.SetAlertDecisions(i)
   318  	return du
   319  }
   320  
   321  // SetNillableAlertDecisions sets the "alert_decisions" field if the given value is not nil.
   322  func (du *DecisionUpdate) SetNillableAlertDecisions(i *int) *DecisionUpdate {
   323  	if i != nil {
   324  		du.SetAlertDecisions(*i)
   325  	}
   326  	return du
   327  }
   328  
   329  // ClearAlertDecisions clears the value of the "alert_decisions" field.
   330  func (du *DecisionUpdate) ClearAlertDecisions() *DecisionUpdate {
   331  	du.mutation.ClearAlertDecisions()
   332  	return du
   333  }
   334  
   335  // SetOwnerID sets the "owner" edge to the Alert entity by ID.
   336  func (du *DecisionUpdate) SetOwnerID(id int) *DecisionUpdate {
   337  	du.mutation.SetOwnerID(id)
   338  	return du
   339  }
   340  
   341  // SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil.
   342  func (du *DecisionUpdate) SetNillableOwnerID(id *int) *DecisionUpdate {
   343  	if id != nil {
   344  		du = du.SetOwnerID(*id)
   345  	}
   346  	return du
   347  }
   348  
   349  // SetOwner sets the "owner" edge to the Alert entity.
   350  func (du *DecisionUpdate) SetOwner(a *Alert) *DecisionUpdate {
   351  	return du.SetOwnerID(a.ID)
   352  }
   353  
   354  // Mutation returns the DecisionMutation object of the builder.
   355  func (du *DecisionUpdate) Mutation() *DecisionMutation {
   356  	return du.mutation
   357  }
   358  
   359  // ClearOwner clears the "owner" edge to the Alert entity.
   360  func (du *DecisionUpdate) ClearOwner() *DecisionUpdate {
   361  	du.mutation.ClearOwner()
   362  	return du
   363  }
   364  
   365  // Save executes the query and returns the number of nodes affected by the update operation.
   366  func (du *DecisionUpdate) Save(ctx context.Context) (int, error) {
   367  	du.defaults()
   368  	return withHooks(ctx, du.sqlSave, du.mutation, du.hooks)
   369  }
   370  
   371  // SaveX is like Save, but panics if an error occurs.
   372  func (du *DecisionUpdate) SaveX(ctx context.Context) int {
   373  	affected, err := du.Save(ctx)
   374  	if err != nil {
   375  		panic(err)
   376  	}
   377  	return affected
   378  }
   379  
   380  // Exec executes the query.
   381  func (du *DecisionUpdate) Exec(ctx context.Context) error {
   382  	_, err := du.Save(ctx)
   383  	return err
   384  }
   385  
   386  // ExecX is like Exec, but panics if an error occurs.
   387  func (du *DecisionUpdate) ExecX(ctx context.Context) {
   388  	if err := du.Exec(ctx); err != nil {
   389  		panic(err)
   390  	}
   391  }
   392  
   393  // defaults sets the default values of the builder before save.
   394  func (du *DecisionUpdate) defaults() {
   395  	if _, ok := du.mutation.CreatedAt(); !ok && !du.mutation.CreatedAtCleared() {
   396  		v := decision.UpdateDefaultCreatedAt()
   397  		du.mutation.SetCreatedAt(v)
   398  	}
   399  	if _, ok := du.mutation.UpdatedAt(); !ok && !du.mutation.UpdatedAtCleared() {
   400  		v := decision.UpdateDefaultUpdatedAt()
   401  		du.mutation.SetUpdatedAt(v)
   402  	}
   403  }
   404  
   405  func (du *DecisionUpdate) sqlSave(ctx context.Context) (n int, err error) {
   406  	_spec := sqlgraph.NewUpdateSpec(decision.Table, decision.Columns, sqlgraph.NewFieldSpec(decision.FieldID, field.TypeInt))
   407  	if ps := du.mutation.predicates; len(ps) > 0 {
   408  		_spec.Predicate = func(selector *sql.Selector) {
   409  			for i := range ps {
   410  				ps[i](selector)
   411  			}
   412  		}
   413  	}
   414  	if value, ok := du.mutation.CreatedAt(); ok {
   415  		_spec.SetField(decision.FieldCreatedAt, field.TypeTime, value)
   416  	}
   417  	if du.mutation.CreatedAtCleared() {
   418  		_spec.ClearField(decision.FieldCreatedAt, field.TypeTime)
   419  	}
   420  	if value, ok := du.mutation.UpdatedAt(); ok {
   421  		_spec.SetField(decision.FieldUpdatedAt, field.TypeTime, value)
   422  	}
   423  	if du.mutation.UpdatedAtCleared() {
   424  		_spec.ClearField(decision.FieldUpdatedAt, field.TypeTime)
   425  	}
   426  	if value, ok := du.mutation.Until(); ok {
   427  		_spec.SetField(decision.FieldUntil, field.TypeTime, value)
   428  	}
   429  	if du.mutation.UntilCleared() {
   430  		_spec.ClearField(decision.FieldUntil, field.TypeTime)
   431  	}
   432  	if value, ok := du.mutation.Scenario(); ok {
   433  		_spec.SetField(decision.FieldScenario, field.TypeString, value)
   434  	}
   435  	if value, ok := du.mutation.GetType(); ok {
   436  		_spec.SetField(decision.FieldType, field.TypeString, value)
   437  	}
   438  	if value, ok := du.mutation.StartIP(); ok {
   439  		_spec.SetField(decision.FieldStartIP, field.TypeInt64, value)
   440  	}
   441  	if value, ok := du.mutation.AddedStartIP(); ok {
   442  		_spec.AddField(decision.FieldStartIP, field.TypeInt64, value)
   443  	}
   444  	if du.mutation.StartIPCleared() {
   445  		_spec.ClearField(decision.FieldStartIP, field.TypeInt64)
   446  	}
   447  	if value, ok := du.mutation.EndIP(); ok {
   448  		_spec.SetField(decision.FieldEndIP, field.TypeInt64, value)
   449  	}
   450  	if value, ok := du.mutation.AddedEndIP(); ok {
   451  		_spec.AddField(decision.FieldEndIP, field.TypeInt64, value)
   452  	}
   453  	if du.mutation.EndIPCleared() {
   454  		_spec.ClearField(decision.FieldEndIP, field.TypeInt64)
   455  	}
   456  	if value, ok := du.mutation.StartSuffix(); ok {
   457  		_spec.SetField(decision.FieldStartSuffix, field.TypeInt64, value)
   458  	}
   459  	if value, ok := du.mutation.AddedStartSuffix(); ok {
   460  		_spec.AddField(decision.FieldStartSuffix, field.TypeInt64, value)
   461  	}
   462  	if du.mutation.StartSuffixCleared() {
   463  		_spec.ClearField(decision.FieldStartSuffix, field.TypeInt64)
   464  	}
   465  	if value, ok := du.mutation.EndSuffix(); ok {
   466  		_spec.SetField(decision.FieldEndSuffix, field.TypeInt64, value)
   467  	}
   468  	if value, ok := du.mutation.AddedEndSuffix(); ok {
   469  		_spec.AddField(decision.FieldEndSuffix, field.TypeInt64, value)
   470  	}
   471  	if du.mutation.EndSuffixCleared() {
   472  		_spec.ClearField(decision.FieldEndSuffix, field.TypeInt64)
   473  	}
   474  	if value, ok := du.mutation.IPSize(); ok {
   475  		_spec.SetField(decision.FieldIPSize, field.TypeInt64, value)
   476  	}
   477  	if value, ok := du.mutation.AddedIPSize(); ok {
   478  		_spec.AddField(decision.FieldIPSize, field.TypeInt64, value)
   479  	}
   480  	if du.mutation.IPSizeCleared() {
   481  		_spec.ClearField(decision.FieldIPSize, field.TypeInt64)
   482  	}
   483  	if value, ok := du.mutation.Scope(); ok {
   484  		_spec.SetField(decision.FieldScope, field.TypeString, value)
   485  	}
   486  	if value, ok := du.mutation.Value(); ok {
   487  		_spec.SetField(decision.FieldValue, field.TypeString, value)
   488  	}
   489  	if value, ok := du.mutation.Origin(); ok {
   490  		_spec.SetField(decision.FieldOrigin, field.TypeString, value)
   491  	}
   492  	if value, ok := du.mutation.Simulated(); ok {
   493  		_spec.SetField(decision.FieldSimulated, field.TypeBool, value)
   494  	}
   495  	if value, ok := du.mutation.UUID(); ok {
   496  		_spec.SetField(decision.FieldUUID, field.TypeString, value)
   497  	}
   498  	if du.mutation.UUIDCleared() {
   499  		_spec.ClearField(decision.FieldUUID, field.TypeString)
   500  	}
   501  	if du.mutation.OwnerCleared() {
   502  		edge := &sqlgraph.EdgeSpec{
   503  			Rel:     sqlgraph.M2O,
   504  			Inverse: true,
   505  			Table:   decision.OwnerTable,
   506  			Columns: []string{decision.OwnerColumn},
   507  			Bidi:    false,
   508  			Target: &sqlgraph.EdgeTarget{
   509  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   510  			},
   511  		}
   512  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   513  	}
   514  	if nodes := du.mutation.OwnerIDs(); len(nodes) > 0 {
   515  		edge := &sqlgraph.EdgeSpec{
   516  			Rel:     sqlgraph.M2O,
   517  			Inverse: true,
   518  			Table:   decision.OwnerTable,
   519  			Columns: []string{decision.OwnerColumn},
   520  			Bidi:    false,
   521  			Target: &sqlgraph.EdgeTarget{
   522  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   523  			},
   524  		}
   525  		for _, k := range nodes {
   526  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   527  		}
   528  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   529  	}
   530  	if n, err = sqlgraph.UpdateNodes(ctx, du.driver, _spec); err != nil {
   531  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   532  			err = &NotFoundError{decision.Label}
   533  		} else if sqlgraph.IsConstraintError(err) {
   534  			err = &ConstraintError{msg: err.Error(), wrap: err}
   535  		}
   536  		return 0, err
   537  	}
   538  	du.mutation.done = true
   539  	return n, nil
   540  }
   541  
   542  // DecisionUpdateOne is the builder for updating a single Decision entity.
   543  type DecisionUpdateOne struct {
   544  	config
   545  	fields   []string
   546  	hooks    []Hook
   547  	mutation *DecisionMutation
   548  }
   549  
   550  // SetCreatedAt sets the "created_at" field.
   551  func (duo *DecisionUpdateOne) SetCreatedAt(t time.Time) *DecisionUpdateOne {
   552  	duo.mutation.SetCreatedAt(t)
   553  	return duo
   554  }
   555  
   556  // ClearCreatedAt clears the value of the "created_at" field.
   557  func (duo *DecisionUpdateOne) ClearCreatedAt() *DecisionUpdateOne {
   558  	duo.mutation.ClearCreatedAt()
   559  	return duo
   560  }
   561  
   562  // SetUpdatedAt sets the "updated_at" field.
   563  func (duo *DecisionUpdateOne) SetUpdatedAt(t time.Time) *DecisionUpdateOne {
   564  	duo.mutation.SetUpdatedAt(t)
   565  	return duo
   566  }
   567  
   568  // ClearUpdatedAt clears the value of the "updated_at" field.
   569  func (duo *DecisionUpdateOne) ClearUpdatedAt() *DecisionUpdateOne {
   570  	duo.mutation.ClearUpdatedAt()
   571  	return duo
   572  }
   573  
   574  // SetUntil sets the "until" field.
   575  func (duo *DecisionUpdateOne) SetUntil(t time.Time) *DecisionUpdateOne {
   576  	duo.mutation.SetUntil(t)
   577  	return duo
   578  }
   579  
   580  // SetNillableUntil sets the "until" field if the given value is not nil.
   581  func (duo *DecisionUpdateOne) SetNillableUntil(t *time.Time) *DecisionUpdateOne {
   582  	if t != nil {
   583  		duo.SetUntil(*t)
   584  	}
   585  	return duo
   586  }
   587  
   588  // ClearUntil clears the value of the "until" field.
   589  func (duo *DecisionUpdateOne) ClearUntil() *DecisionUpdateOne {
   590  	duo.mutation.ClearUntil()
   591  	return duo
   592  }
   593  
   594  // SetScenario sets the "scenario" field.
   595  func (duo *DecisionUpdateOne) SetScenario(s string) *DecisionUpdateOne {
   596  	duo.mutation.SetScenario(s)
   597  	return duo
   598  }
   599  
   600  // SetNillableScenario sets the "scenario" field if the given value is not nil.
   601  func (duo *DecisionUpdateOne) SetNillableScenario(s *string) *DecisionUpdateOne {
   602  	if s != nil {
   603  		duo.SetScenario(*s)
   604  	}
   605  	return duo
   606  }
   607  
   608  // SetType sets the "type" field.
   609  func (duo *DecisionUpdateOne) SetType(s string) *DecisionUpdateOne {
   610  	duo.mutation.SetType(s)
   611  	return duo
   612  }
   613  
   614  // SetNillableType sets the "type" field if the given value is not nil.
   615  func (duo *DecisionUpdateOne) SetNillableType(s *string) *DecisionUpdateOne {
   616  	if s != nil {
   617  		duo.SetType(*s)
   618  	}
   619  	return duo
   620  }
   621  
   622  // SetStartIP sets the "start_ip" field.
   623  func (duo *DecisionUpdateOne) SetStartIP(i int64) *DecisionUpdateOne {
   624  	duo.mutation.ResetStartIP()
   625  	duo.mutation.SetStartIP(i)
   626  	return duo
   627  }
   628  
   629  // SetNillableStartIP sets the "start_ip" field if the given value is not nil.
   630  func (duo *DecisionUpdateOne) SetNillableStartIP(i *int64) *DecisionUpdateOne {
   631  	if i != nil {
   632  		duo.SetStartIP(*i)
   633  	}
   634  	return duo
   635  }
   636  
   637  // AddStartIP adds i to the "start_ip" field.
   638  func (duo *DecisionUpdateOne) AddStartIP(i int64) *DecisionUpdateOne {
   639  	duo.mutation.AddStartIP(i)
   640  	return duo
   641  }
   642  
   643  // ClearStartIP clears the value of the "start_ip" field.
   644  func (duo *DecisionUpdateOne) ClearStartIP() *DecisionUpdateOne {
   645  	duo.mutation.ClearStartIP()
   646  	return duo
   647  }
   648  
   649  // SetEndIP sets the "end_ip" field.
   650  func (duo *DecisionUpdateOne) SetEndIP(i int64) *DecisionUpdateOne {
   651  	duo.mutation.ResetEndIP()
   652  	duo.mutation.SetEndIP(i)
   653  	return duo
   654  }
   655  
   656  // SetNillableEndIP sets the "end_ip" field if the given value is not nil.
   657  func (duo *DecisionUpdateOne) SetNillableEndIP(i *int64) *DecisionUpdateOne {
   658  	if i != nil {
   659  		duo.SetEndIP(*i)
   660  	}
   661  	return duo
   662  }
   663  
   664  // AddEndIP adds i to the "end_ip" field.
   665  func (duo *DecisionUpdateOne) AddEndIP(i int64) *DecisionUpdateOne {
   666  	duo.mutation.AddEndIP(i)
   667  	return duo
   668  }
   669  
   670  // ClearEndIP clears the value of the "end_ip" field.
   671  func (duo *DecisionUpdateOne) ClearEndIP() *DecisionUpdateOne {
   672  	duo.mutation.ClearEndIP()
   673  	return duo
   674  }
   675  
   676  // SetStartSuffix sets the "start_suffix" field.
   677  func (duo *DecisionUpdateOne) SetStartSuffix(i int64) *DecisionUpdateOne {
   678  	duo.mutation.ResetStartSuffix()
   679  	duo.mutation.SetStartSuffix(i)
   680  	return duo
   681  }
   682  
   683  // SetNillableStartSuffix sets the "start_suffix" field if the given value is not nil.
   684  func (duo *DecisionUpdateOne) SetNillableStartSuffix(i *int64) *DecisionUpdateOne {
   685  	if i != nil {
   686  		duo.SetStartSuffix(*i)
   687  	}
   688  	return duo
   689  }
   690  
   691  // AddStartSuffix adds i to the "start_suffix" field.
   692  func (duo *DecisionUpdateOne) AddStartSuffix(i int64) *DecisionUpdateOne {
   693  	duo.mutation.AddStartSuffix(i)
   694  	return duo
   695  }
   696  
   697  // ClearStartSuffix clears the value of the "start_suffix" field.
   698  func (duo *DecisionUpdateOne) ClearStartSuffix() *DecisionUpdateOne {
   699  	duo.mutation.ClearStartSuffix()
   700  	return duo
   701  }
   702  
   703  // SetEndSuffix sets the "end_suffix" field.
   704  func (duo *DecisionUpdateOne) SetEndSuffix(i int64) *DecisionUpdateOne {
   705  	duo.mutation.ResetEndSuffix()
   706  	duo.mutation.SetEndSuffix(i)
   707  	return duo
   708  }
   709  
   710  // SetNillableEndSuffix sets the "end_suffix" field if the given value is not nil.
   711  func (duo *DecisionUpdateOne) SetNillableEndSuffix(i *int64) *DecisionUpdateOne {
   712  	if i != nil {
   713  		duo.SetEndSuffix(*i)
   714  	}
   715  	return duo
   716  }
   717  
   718  // AddEndSuffix adds i to the "end_suffix" field.
   719  func (duo *DecisionUpdateOne) AddEndSuffix(i int64) *DecisionUpdateOne {
   720  	duo.mutation.AddEndSuffix(i)
   721  	return duo
   722  }
   723  
   724  // ClearEndSuffix clears the value of the "end_suffix" field.
   725  func (duo *DecisionUpdateOne) ClearEndSuffix() *DecisionUpdateOne {
   726  	duo.mutation.ClearEndSuffix()
   727  	return duo
   728  }
   729  
   730  // SetIPSize sets the "ip_size" field.
   731  func (duo *DecisionUpdateOne) SetIPSize(i int64) *DecisionUpdateOne {
   732  	duo.mutation.ResetIPSize()
   733  	duo.mutation.SetIPSize(i)
   734  	return duo
   735  }
   736  
   737  // SetNillableIPSize sets the "ip_size" field if the given value is not nil.
   738  func (duo *DecisionUpdateOne) SetNillableIPSize(i *int64) *DecisionUpdateOne {
   739  	if i != nil {
   740  		duo.SetIPSize(*i)
   741  	}
   742  	return duo
   743  }
   744  
   745  // AddIPSize adds i to the "ip_size" field.
   746  func (duo *DecisionUpdateOne) AddIPSize(i int64) *DecisionUpdateOne {
   747  	duo.mutation.AddIPSize(i)
   748  	return duo
   749  }
   750  
   751  // ClearIPSize clears the value of the "ip_size" field.
   752  func (duo *DecisionUpdateOne) ClearIPSize() *DecisionUpdateOne {
   753  	duo.mutation.ClearIPSize()
   754  	return duo
   755  }
   756  
   757  // SetScope sets the "scope" field.
   758  func (duo *DecisionUpdateOne) SetScope(s string) *DecisionUpdateOne {
   759  	duo.mutation.SetScope(s)
   760  	return duo
   761  }
   762  
   763  // SetNillableScope sets the "scope" field if the given value is not nil.
   764  func (duo *DecisionUpdateOne) SetNillableScope(s *string) *DecisionUpdateOne {
   765  	if s != nil {
   766  		duo.SetScope(*s)
   767  	}
   768  	return duo
   769  }
   770  
   771  // SetValue sets the "value" field.
   772  func (duo *DecisionUpdateOne) SetValue(s string) *DecisionUpdateOne {
   773  	duo.mutation.SetValue(s)
   774  	return duo
   775  }
   776  
   777  // SetNillableValue sets the "value" field if the given value is not nil.
   778  func (duo *DecisionUpdateOne) SetNillableValue(s *string) *DecisionUpdateOne {
   779  	if s != nil {
   780  		duo.SetValue(*s)
   781  	}
   782  	return duo
   783  }
   784  
   785  // SetOrigin sets the "origin" field.
   786  func (duo *DecisionUpdateOne) SetOrigin(s string) *DecisionUpdateOne {
   787  	duo.mutation.SetOrigin(s)
   788  	return duo
   789  }
   790  
   791  // SetNillableOrigin sets the "origin" field if the given value is not nil.
   792  func (duo *DecisionUpdateOne) SetNillableOrigin(s *string) *DecisionUpdateOne {
   793  	if s != nil {
   794  		duo.SetOrigin(*s)
   795  	}
   796  	return duo
   797  }
   798  
   799  // SetSimulated sets the "simulated" field.
   800  func (duo *DecisionUpdateOne) SetSimulated(b bool) *DecisionUpdateOne {
   801  	duo.mutation.SetSimulated(b)
   802  	return duo
   803  }
   804  
   805  // SetNillableSimulated sets the "simulated" field if the given value is not nil.
   806  func (duo *DecisionUpdateOne) SetNillableSimulated(b *bool) *DecisionUpdateOne {
   807  	if b != nil {
   808  		duo.SetSimulated(*b)
   809  	}
   810  	return duo
   811  }
   812  
   813  // SetUUID sets the "uuid" field.
   814  func (duo *DecisionUpdateOne) SetUUID(s string) *DecisionUpdateOne {
   815  	duo.mutation.SetUUID(s)
   816  	return duo
   817  }
   818  
   819  // SetNillableUUID sets the "uuid" field if the given value is not nil.
   820  func (duo *DecisionUpdateOne) SetNillableUUID(s *string) *DecisionUpdateOne {
   821  	if s != nil {
   822  		duo.SetUUID(*s)
   823  	}
   824  	return duo
   825  }
   826  
   827  // ClearUUID clears the value of the "uuid" field.
   828  func (duo *DecisionUpdateOne) ClearUUID() *DecisionUpdateOne {
   829  	duo.mutation.ClearUUID()
   830  	return duo
   831  }
   832  
   833  // SetAlertDecisions sets the "alert_decisions" field.
   834  func (duo *DecisionUpdateOne) SetAlertDecisions(i int) *DecisionUpdateOne {
   835  	duo.mutation.SetAlertDecisions(i)
   836  	return duo
   837  }
   838  
   839  // SetNillableAlertDecisions sets the "alert_decisions" field if the given value is not nil.
   840  func (duo *DecisionUpdateOne) SetNillableAlertDecisions(i *int) *DecisionUpdateOne {
   841  	if i != nil {
   842  		duo.SetAlertDecisions(*i)
   843  	}
   844  	return duo
   845  }
   846  
   847  // ClearAlertDecisions clears the value of the "alert_decisions" field.
   848  func (duo *DecisionUpdateOne) ClearAlertDecisions() *DecisionUpdateOne {
   849  	duo.mutation.ClearAlertDecisions()
   850  	return duo
   851  }
   852  
   853  // SetOwnerID sets the "owner" edge to the Alert entity by ID.
   854  func (duo *DecisionUpdateOne) SetOwnerID(id int) *DecisionUpdateOne {
   855  	duo.mutation.SetOwnerID(id)
   856  	return duo
   857  }
   858  
   859  // SetNillableOwnerID sets the "owner" edge to the Alert entity by ID if the given value is not nil.
   860  func (duo *DecisionUpdateOne) SetNillableOwnerID(id *int) *DecisionUpdateOne {
   861  	if id != nil {
   862  		duo = duo.SetOwnerID(*id)
   863  	}
   864  	return duo
   865  }
   866  
   867  // SetOwner sets the "owner" edge to the Alert entity.
   868  func (duo *DecisionUpdateOne) SetOwner(a *Alert) *DecisionUpdateOne {
   869  	return duo.SetOwnerID(a.ID)
   870  }
   871  
   872  // Mutation returns the DecisionMutation object of the builder.
   873  func (duo *DecisionUpdateOne) Mutation() *DecisionMutation {
   874  	return duo.mutation
   875  }
   876  
   877  // ClearOwner clears the "owner" edge to the Alert entity.
   878  func (duo *DecisionUpdateOne) ClearOwner() *DecisionUpdateOne {
   879  	duo.mutation.ClearOwner()
   880  	return duo
   881  }
   882  
   883  // Where appends a list predicates to the DecisionUpdate builder.
   884  func (duo *DecisionUpdateOne) Where(ps ...predicate.Decision) *DecisionUpdateOne {
   885  	duo.mutation.Where(ps...)
   886  	return duo
   887  }
   888  
   889  // Select allows selecting one or more fields (columns) of the returned entity.
   890  // The default is selecting all fields defined in the entity schema.
   891  func (duo *DecisionUpdateOne) Select(field string, fields ...string) *DecisionUpdateOne {
   892  	duo.fields = append([]string{field}, fields...)
   893  	return duo
   894  }
   895  
   896  // Save executes the query and returns the updated Decision entity.
   897  func (duo *DecisionUpdateOne) Save(ctx context.Context) (*Decision, error) {
   898  	duo.defaults()
   899  	return withHooks(ctx, duo.sqlSave, duo.mutation, duo.hooks)
   900  }
   901  
   902  // SaveX is like Save, but panics if an error occurs.
   903  func (duo *DecisionUpdateOne) SaveX(ctx context.Context) *Decision {
   904  	node, err := duo.Save(ctx)
   905  	if err != nil {
   906  		panic(err)
   907  	}
   908  	return node
   909  }
   910  
   911  // Exec executes the query on the entity.
   912  func (duo *DecisionUpdateOne) Exec(ctx context.Context) error {
   913  	_, err := duo.Save(ctx)
   914  	return err
   915  }
   916  
   917  // ExecX is like Exec, but panics if an error occurs.
   918  func (duo *DecisionUpdateOne) ExecX(ctx context.Context) {
   919  	if err := duo.Exec(ctx); err != nil {
   920  		panic(err)
   921  	}
   922  }
   923  
   924  // defaults sets the default values of the builder before save.
   925  func (duo *DecisionUpdateOne) defaults() {
   926  	if _, ok := duo.mutation.CreatedAt(); !ok && !duo.mutation.CreatedAtCleared() {
   927  		v := decision.UpdateDefaultCreatedAt()
   928  		duo.mutation.SetCreatedAt(v)
   929  	}
   930  	if _, ok := duo.mutation.UpdatedAt(); !ok && !duo.mutation.UpdatedAtCleared() {
   931  		v := decision.UpdateDefaultUpdatedAt()
   932  		duo.mutation.SetUpdatedAt(v)
   933  	}
   934  }
   935  
   936  func (duo *DecisionUpdateOne) sqlSave(ctx context.Context) (_node *Decision, err error) {
   937  	_spec := sqlgraph.NewUpdateSpec(decision.Table, decision.Columns, sqlgraph.NewFieldSpec(decision.FieldID, field.TypeInt))
   938  	id, ok := duo.mutation.ID()
   939  	if !ok {
   940  		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Decision.id" for update`)}
   941  	}
   942  	_spec.Node.ID.Value = id
   943  	if fields := duo.fields; len(fields) > 0 {
   944  		_spec.Node.Columns = make([]string, 0, len(fields))
   945  		_spec.Node.Columns = append(_spec.Node.Columns, decision.FieldID)
   946  		for _, f := range fields {
   947  			if !decision.ValidColumn(f) {
   948  				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
   949  			}
   950  			if f != decision.FieldID {
   951  				_spec.Node.Columns = append(_spec.Node.Columns, f)
   952  			}
   953  		}
   954  	}
   955  	if ps := duo.mutation.predicates; len(ps) > 0 {
   956  		_spec.Predicate = func(selector *sql.Selector) {
   957  			for i := range ps {
   958  				ps[i](selector)
   959  			}
   960  		}
   961  	}
   962  	if value, ok := duo.mutation.CreatedAt(); ok {
   963  		_spec.SetField(decision.FieldCreatedAt, field.TypeTime, value)
   964  	}
   965  	if duo.mutation.CreatedAtCleared() {
   966  		_spec.ClearField(decision.FieldCreatedAt, field.TypeTime)
   967  	}
   968  	if value, ok := duo.mutation.UpdatedAt(); ok {
   969  		_spec.SetField(decision.FieldUpdatedAt, field.TypeTime, value)
   970  	}
   971  	if duo.mutation.UpdatedAtCleared() {
   972  		_spec.ClearField(decision.FieldUpdatedAt, field.TypeTime)
   973  	}
   974  	if value, ok := duo.mutation.Until(); ok {
   975  		_spec.SetField(decision.FieldUntil, field.TypeTime, value)
   976  	}
   977  	if duo.mutation.UntilCleared() {
   978  		_spec.ClearField(decision.FieldUntil, field.TypeTime)
   979  	}
   980  	if value, ok := duo.mutation.Scenario(); ok {
   981  		_spec.SetField(decision.FieldScenario, field.TypeString, value)
   982  	}
   983  	if value, ok := duo.mutation.GetType(); ok {
   984  		_spec.SetField(decision.FieldType, field.TypeString, value)
   985  	}
   986  	if value, ok := duo.mutation.StartIP(); ok {
   987  		_spec.SetField(decision.FieldStartIP, field.TypeInt64, value)
   988  	}
   989  	if value, ok := duo.mutation.AddedStartIP(); ok {
   990  		_spec.AddField(decision.FieldStartIP, field.TypeInt64, value)
   991  	}
   992  	if duo.mutation.StartIPCleared() {
   993  		_spec.ClearField(decision.FieldStartIP, field.TypeInt64)
   994  	}
   995  	if value, ok := duo.mutation.EndIP(); ok {
   996  		_spec.SetField(decision.FieldEndIP, field.TypeInt64, value)
   997  	}
   998  	if value, ok := duo.mutation.AddedEndIP(); ok {
   999  		_spec.AddField(decision.FieldEndIP, field.TypeInt64, value)
  1000  	}
  1001  	if duo.mutation.EndIPCleared() {
  1002  		_spec.ClearField(decision.FieldEndIP, field.TypeInt64)
  1003  	}
  1004  	if value, ok := duo.mutation.StartSuffix(); ok {
  1005  		_spec.SetField(decision.FieldStartSuffix, field.TypeInt64, value)
  1006  	}
  1007  	if value, ok := duo.mutation.AddedStartSuffix(); ok {
  1008  		_spec.AddField(decision.FieldStartSuffix, field.TypeInt64, value)
  1009  	}
  1010  	if duo.mutation.StartSuffixCleared() {
  1011  		_spec.ClearField(decision.FieldStartSuffix, field.TypeInt64)
  1012  	}
  1013  	if value, ok := duo.mutation.EndSuffix(); ok {
  1014  		_spec.SetField(decision.FieldEndSuffix, field.TypeInt64, value)
  1015  	}
  1016  	if value, ok := duo.mutation.AddedEndSuffix(); ok {
  1017  		_spec.AddField(decision.FieldEndSuffix, field.TypeInt64, value)
  1018  	}
  1019  	if duo.mutation.EndSuffixCleared() {
  1020  		_spec.ClearField(decision.FieldEndSuffix, field.TypeInt64)
  1021  	}
  1022  	if value, ok := duo.mutation.IPSize(); ok {
  1023  		_spec.SetField(decision.FieldIPSize, field.TypeInt64, value)
  1024  	}
  1025  	if value, ok := duo.mutation.AddedIPSize(); ok {
  1026  		_spec.AddField(decision.FieldIPSize, field.TypeInt64, value)
  1027  	}
  1028  	if duo.mutation.IPSizeCleared() {
  1029  		_spec.ClearField(decision.FieldIPSize, field.TypeInt64)
  1030  	}
  1031  	if value, ok := duo.mutation.Scope(); ok {
  1032  		_spec.SetField(decision.FieldScope, field.TypeString, value)
  1033  	}
  1034  	if value, ok := duo.mutation.Value(); ok {
  1035  		_spec.SetField(decision.FieldValue, field.TypeString, value)
  1036  	}
  1037  	if value, ok := duo.mutation.Origin(); ok {
  1038  		_spec.SetField(decision.FieldOrigin, field.TypeString, value)
  1039  	}
  1040  	if value, ok := duo.mutation.Simulated(); ok {
  1041  		_spec.SetField(decision.FieldSimulated, field.TypeBool, value)
  1042  	}
  1043  	if value, ok := duo.mutation.UUID(); ok {
  1044  		_spec.SetField(decision.FieldUUID, field.TypeString, value)
  1045  	}
  1046  	if duo.mutation.UUIDCleared() {
  1047  		_spec.ClearField(decision.FieldUUID, field.TypeString)
  1048  	}
  1049  	if duo.mutation.OwnerCleared() {
  1050  		edge := &sqlgraph.EdgeSpec{
  1051  			Rel:     sqlgraph.M2O,
  1052  			Inverse: true,
  1053  			Table:   decision.OwnerTable,
  1054  			Columns: []string{decision.OwnerColumn},
  1055  			Bidi:    false,
  1056  			Target: &sqlgraph.EdgeTarget{
  1057  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
  1058  			},
  1059  		}
  1060  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1061  	}
  1062  	if nodes := duo.mutation.OwnerIDs(); len(nodes) > 0 {
  1063  		edge := &sqlgraph.EdgeSpec{
  1064  			Rel:     sqlgraph.M2O,
  1065  			Inverse: true,
  1066  			Table:   decision.OwnerTable,
  1067  			Columns: []string{decision.OwnerColumn},
  1068  			Bidi:    false,
  1069  			Target: &sqlgraph.EdgeTarget{
  1070  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
  1071  			},
  1072  		}
  1073  		for _, k := range nodes {
  1074  			edge.Target.Nodes = append(edge.Target.Nodes, k)
  1075  		}
  1076  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
  1077  	}
  1078  	_node = &Decision{config: duo.config}
  1079  	_spec.Assign = _node.assignValues
  1080  	_spec.ScanValues = _node.scanValues
  1081  	if err = sqlgraph.UpdateNode(ctx, duo.driver, _spec); err != nil {
  1082  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1083  			err = &NotFoundError{decision.Label}
  1084  		} else if sqlgraph.IsConstraintError(err) {
  1085  			err = &ConstraintError{msg: err.Error(), wrap: err}
  1086  		}
  1087  		return nil, err
  1088  	}
  1089  	duo.mutation.done = true
  1090  	return _node, nil
  1091  }