github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/machine_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/machine"
    16  	"github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate"
    17  )
    18  
    19  // MachineUpdate is the builder for updating Machine entities.
    20  type MachineUpdate struct {
    21  	config
    22  	hooks    []Hook
    23  	mutation *MachineMutation
    24  }
    25  
    26  // Where appends a list predicates to the MachineUpdate builder.
    27  func (mu *MachineUpdate) Where(ps ...predicate.Machine) *MachineUpdate {
    28  	mu.mutation.Where(ps...)
    29  	return mu
    30  }
    31  
    32  // SetCreatedAt sets the "created_at" field.
    33  func (mu *MachineUpdate) SetCreatedAt(t time.Time) *MachineUpdate {
    34  	mu.mutation.SetCreatedAt(t)
    35  	return mu
    36  }
    37  
    38  // ClearCreatedAt clears the value of the "created_at" field.
    39  func (mu *MachineUpdate) ClearCreatedAt() *MachineUpdate {
    40  	mu.mutation.ClearCreatedAt()
    41  	return mu
    42  }
    43  
    44  // SetUpdatedAt sets the "updated_at" field.
    45  func (mu *MachineUpdate) SetUpdatedAt(t time.Time) *MachineUpdate {
    46  	mu.mutation.SetUpdatedAt(t)
    47  	return mu
    48  }
    49  
    50  // ClearUpdatedAt clears the value of the "updated_at" field.
    51  func (mu *MachineUpdate) ClearUpdatedAt() *MachineUpdate {
    52  	mu.mutation.ClearUpdatedAt()
    53  	return mu
    54  }
    55  
    56  // SetLastPush sets the "last_push" field.
    57  func (mu *MachineUpdate) SetLastPush(t time.Time) *MachineUpdate {
    58  	mu.mutation.SetLastPush(t)
    59  	return mu
    60  }
    61  
    62  // ClearLastPush clears the value of the "last_push" field.
    63  func (mu *MachineUpdate) ClearLastPush() *MachineUpdate {
    64  	mu.mutation.ClearLastPush()
    65  	return mu
    66  }
    67  
    68  // SetLastHeartbeat sets the "last_heartbeat" field.
    69  func (mu *MachineUpdate) SetLastHeartbeat(t time.Time) *MachineUpdate {
    70  	mu.mutation.SetLastHeartbeat(t)
    71  	return mu
    72  }
    73  
    74  // ClearLastHeartbeat clears the value of the "last_heartbeat" field.
    75  func (mu *MachineUpdate) ClearLastHeartbeat() *MachineUpdate {
    76  	mu.mutation.ClearLastHeartbeat()
    77  	return mu
    78  }
    79  
    80  // SetMachineId sets the "machineId" field.
    81  func (mu *MachineUpdate) SetMachineId(s string) *MachineUpdate {
    82  	mu.mutation.SetMachineId(s)
    83  	return mu
    84  }
    85  
    86  // SetNillableMachineId sets the "machineId" field if the given value is not nil.
    87  func (mu *MachineUpdate) SetNillableMachineId(s *string) *MachineUpdate {
    88  	if s != nil {
    89  		mu.SetMachineId(*s)
    90  	}
    91  	return mu
    92  }
    93  
    94  // SetPassword sets the "password" field.
    95  func (mu *MachineUpdate) SetPassword(s string) *MachineUpdate {
    96  	mu.mutation.SetPassword(s)
    97  	return mu
    98  }
    99  
   100  // SetNillablePassword sets the "password" field if the given value is not nil.
   101  func (mu *MachineUpdate) SetNillablePassword(s *string) *MachineUpdate {
   102  	if s != nil {
   103  		mu.SetPassword(*s)
   104  	}
   105  	return mu
   106  }
   107  
   108  // SetIpAddress sets the "ipAddress" field.
   109  func (mu *MachineUpdate) SetIpAddress(s string) *MachineUpdate {
   110  	mu.mutation.SetIpAddress(s)
   111  	return mu
   112  }
   113  
   114  // SetNillableIpAddress sets the "ipAddress" field if the given value is not nil.
   115  func (mu *MachineUpdate) SetNillableIpAddress(s *string) *MachineUpdate {
   116  	if s != nil {
   117  		mu.SetIpAddress(*s)
   118  	}
   119  	return mu
   120  }
   121  
   122  // SetScenarios sets the "scenarios" field.
   123  func (mu *MachineUpdate) SetScenarios(s string) *MachineUpdate {
   124  	mu.mutation.SetScenarios(s)
   125  	return mu
   126  }
   127  
   128  // SetNillableScenarios sets the "scenarios" field if the given value is not nil.
   129  func (mu *MachineUpdate) SetNillableScenarios(s *string) *MachineUpdate {
   130  	if s != nil {
   131  		mu.SetScenarios(*s)
   132  	}
   133  	return mu
   134  }
   135  
   136  // ClearScenarios clears the value of the "scenarios" field.
   137  func (mu *MachineUpdate) ClearScenarios() *MachineUpdate {
   138  	mu.mutation.ClearScenarios()
   139  	return mu
   140  }
   141  
   142  // SetVersion sets the "version" field.
   143  func (mu *MachineUpdate) SetVersion(s string) *MachineUpdate {
   144  	mu.mutation.SetVersion(s)
   145  	return mu
   146  }
   147  
   148  // SetNillableVersion sets the "version" field if the given value is not nil.
   149  func (mu *MachineUpdate) SetNillableVersion(s *string) *MachineUpdate {
   150  	if s != nil {
   151  		mu.SetVersion(*s)
   152  	}
   153  	return mu
   154  }
   155  
   156  // ClearVersion clears the value of the "version" field.
   157  func (mu *MachineUpdate) ClearVersion() *MachineUpdate {
   158  	mu.mutation.ClearVersion()
   159  	return mu
   160  }
   161  
   162  // SetIsValidated sets the "isValidated" field.
   163  func (mu *MachineUpdate) SetIsValidated(b bool) *MachineUpdate {
   164  	mu.mutation.SetIsValidated(b)
   165  	return mu
   166  }
   167  
   168  // SetNillableIsValidated sets the "isValidated" field if the given value is not nil.
   169  func (mu *MachineUpdate) SetNillableIsValidated(b *bool) *MachineUpdate {
   170  	if b != nil {
   171  		mu.SetIsValidated(*b)
   172  	}
   173  	return mu
   174  }
   175  
   176  // SetStatus sets the "status" field.
   177  func (mu *MachineUpdate) SetStatus(s string) *MachineUpdate {
   178  	mu.mutation.SetStatus(s)
   179  	return mu
   180  }
   181  
   182  // SetNillableStatus sets the "status" field if the given value is not nil.
   183  func (mu *MachineUpdate) SetNillableStatus(s *string) *MachineUpdate {
   184  	if s != nil {
   185  		mu.SetStatus(*s)
   186  	}
   187  	return mu
   188  }
   189  
   190  // ClearStatus clears the value of the "status" field.
   191  func (mu *MachineUpdate) ClearStatus() *MachineUpdate {
   192  	mu.mutation.ClearStatus()
   193  	return mu
   194  }
   195  
   196  // SetAuthType sets the "auth_type" field.
   197  func (mu *MachineUpdate) SetAuthType(s string) *MachineUpdate {
   198  	mu.mutation.SetAuthType(s)
   199  	return mu
   200  }
   201  
   202  // SetNillableAuthType sets the "auth_type" field if the given value is not nil.
   203  func (mu *MachineUpdate) SetNillableAuthType(s *string) *MachineUpdate {
   204  	if s != nil {
   205  		mu.SetAuthType(*s)
   206  	}
   207  	return mu
   208  }
   209  
   210  // AddAlertIDs adds the "alerts" edge to the Alert entity by IDs.
   211  func (mu *MachineUpdate) AddAlertIDs(ids ...int) *MachineUpdate {
   212  	mu.mutation.AddAlertIDs(ids...)
   213  	return mu
   214  }
   215  
   216  // AddAlerts adds the "alerts" edges to the Alert entity.
   217  func (mu *MachineUpdate) AddAlerts(a ...*Alert) *MachineUpdate {
   218  	ids := make([]int, len(a))
   219  	for i := range a {
   220  		ids[i] = a[i].ID
   221  	}
   222  	return mu.AddAlertIDs(ids...)
   223  }
   224  
   225  // Mutation returns the MachineMutation object of the builder.
   226  func (mu *MachineUpdate) Mutation() *MachineMutation {
   227  	return mu.mutation
   228  }
   229  
   230  // ClearAlerts clears all "alerts" edges to the Alert entity.
   231  func (mu *MachineUpdate) ClearAlerts() *MachineUpdate {
   232  	mu.mutation.ClearAlerts()
   233  	return mu
   234  }
   235  
   236  // RemoveAlertIDs removes the "alerts" edge to Alert entities by IDs.
   237  func (mu *MachineUpdate) RemoveAlertIDs(ids ...int) *MachineUpdate {
   238  	mu.mutation.RemoveAlertIDs(ids...)
   239  	return mu
   240  }
   241  
   242  // RemoveAlerts removes "alerts" edges to Alert entities.
   243  func (mu *MachineUpdate) RemoveAlerts(a ...*Alert) *MachineUpdate {
   244  	ids := make([]int, len(a))
   245  	for i := range a {
   246  		ids[i] = a[i].ID
   247  	}
   248  	return mu.RemoveAlertIDs(ids...)
   249  }
   250  
   251  // Save executes the query and returns the number of nodes affected by the update operation.
   252  func (mu *MachineUpdate) Save(ctx context.Context) (int, error) {
   253  	mu.defaults()
   254  	return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks)
   255  }
   256  
   257  // SaveX is like Save, but panics if an error occurs.
   258  func (mu *MachineUpdate) SaveX(ctx context.Context) int {
   259  	affected, err := mu.Save(ctx)
   260  	if err != nil {
   261  		panic(err)
   262  	}
   263  	return affected
   264  }
   265  
   266  // Exec executes the query.
   267  func (mu *MachineUpdate) Exec(ctx context.Context) error {
   268  	_, err := mu.Save(ctx)
   269  	return err
   270  }
   271  
   272  // ExecX is like Exec, but panics if an error occurs.
   273  func (mu *MachineUpdate) ExecX(ctx context.Context) {
   274  	if err := mu.Exec(ctx); err != nil {
   275  		panic(err)
   276  	}
   277  }
   278  
   279  // defaults sets the default values of the builder before save.
   280  func (mu *MachineUpdate) defaults() {
   281  	if _, ok := mu.mutation.CreatedAt(); !ok && !mu.mutation.CreatedAtCleared() {
   282  		v := machine.UpdateDefaultCreatedAt()
   283  		mu.mutation.SetCreatedAt(v)
   284  	}
   285  	if _, ok := mu.mutation.UpdatedAt(); !ok && !mu.mutation.UpdatedAtCleared() {
   286  		v := machine.UpdateDefaultUpdatedAt()
   287  		mu.mutation.SetUpdatedAt(v)
   288  	}
   289  	if _, ok := mu.mutation.LastPush(); !ok && !mu.mutation.LastPushCleared() {
   290  		v := machine.UpdateDefaultLastPush()
   291  		mu.mutation.SetLastPush(v)
   292  	}
   293  	if _, ok := mu.mutation.LastHeartbeat(); !ok && !mu.mutation.LastHeartbeatCleared() {
   294  		v := machine.UpdateDefaultLastHeartbeat()
   295  		mu.mutation.SetLastHeartbeat(v)
   296  	}
   297  }
   298  
   299  // check runs all checks and user-defined validators on the builder.
   300  func (mu *MachineUpdate) check() error {
   301  	if v, ok := mu.mutation.Scenarios(); ok {
   302  		if err := machine.ScenariosValidator(v); err != nil {
   303  			return &ValidationError{Name: "scenarios", err: fmt.Errorf(`ent: validator failed for field "Machine.scenarios": %w`, err)}
   304  		}
   305  	}
   306  	return nil
   307  }
   308  
   309  func (mu *MachineUpdate) sqlSave(ctx context.Context) (n int, err error) {
   310  	if err := mu.check(); err != nil {
   311  		return n, err
   312  	}
   313  	_spec := sqlgraph.NewUpdateSpec(machine.Table, machine.Columns, sqlgraph.NewFieldSpec(machine.FieldID, field.TypeInt))
   314  	if ps := mu.mutation.predicates; len(ps) > 0 {
   315  		_spec.Predicate = func(selector *sql.Selector) {
   316  			for i := range ps {
   317  				ps[i](selector)
   318  			}
   319  		}
   320  	}
   321  	if value, ok := mu.mutation.CreatedAt(); ok {
   322  		_spec.SetField(machine.FieldCreatedAt, field.TypeTime, value)
   323  	}
   324  	if mu.mutation.CreatedAtCleared() {
   325  		_spec.ClearField(machine.FieldCreatedAt, field.TypeTime)
   326  	}
   327  	if value, ok := mu.mutation.UpdatedAt(); ok {
   328  		_spec.SetField(machine.FieldUpdatedAt, field.TypeTime, value)
   329  	}
   330  	if mu.mutation.UpdatedAtCleared() {
   331  		_spec.ClearField(machine.FieldUpdatedAt, field.TypeTime)
   332  	}
   333  	if value, ok := mu.mutation.LastPush(); ok {
   334  		_spec.SetField(machine.FieldLastPush, field.TypeTime, value)
   335  	}
   336  	if mu.mutation.LastPushCleared() {
   337  		_spec.ClearField(machine.FieldLastPush, field.TypeTime)
   338  	}
   339  	if value, ok := mu.mutation.LastHeartbeat(); ok {
   340  		_spec.SetField(machine.FieldLastHeartbeat, field.TypeTime, value)
   341  	}
   342  	if mu.mutation.LastHeartbeatCleared() {
   343  		_spec.ClearField(machine.FieldLastHeartbeat, field.TypeTime)
   344  	}
   345  	if value, ok := mu.mutation.MachineId(); ok {
   346  		_spec.SetField(machine.FieldMachineId, field.TypeString, value)
   347  	}
   348  	if value, ok := mu.mutation.Password(); ok {
   349  		_spec.SetField(machine.FieldPassword, field.TypeString, value)
   350  	}
   351  	if value, ok := mu.mutation.IpAddress(); ok {
   352  		_spec.SetField(machine.FieldIpAddress, field.TypeString, value)
   353  	}
   354  	if value, ok := mu.mutation.Scenarios(); ok {
   355  		_spec.SetField(machine.FieldScenarios, field.TypeString, value)
   356  	}
   357  	if mu.mutation.ScenariosCleared() {
   358  		_spec.ClearField(machine.FieldScenarios, field.TypeString)
   359  	}
   360  	if value, ok := mu.mutation.Version(); ok {
   361  		_spec.SetField(machine.FieldVersion, field.TypeString, value)
   362  	}
   363  	if mu.mutation.VersionCleared() {
   364  		_spec.ClearField(machine.FieldVersion, field.TypeString)
   365  	}
   366  	if value, ok := mu.mutation.IsValidated(); ok {
   367  		_spec.SetField(machine.FieldIsValidated, field.TypeBool, value)
   368  	}
   369  	if value, ok := mu.mutation.Status(); ok {
   370  		_spec.SetField(machine.FieldStatus, field.TypeString, value)
   371  	}
   372  	if mu.mutation.StatusCleared() {
   373  		_spec.ClearField(machine.FieldStatus, field.TypeString)
   374  	}
   375  	if value, ok := mu.mutation.AuthType(); ok {
   376  		_spec.SetField(machine.FieldAuthType, field.TypeString, value)
   377  	}
   378  	if mu.mutation.AlertsCleared() {
   379  		edge := &sqlgraph.EdgeSpec{
   380  			Rel:     sqlgraph.O2M,
   381  			Inverse: false,
   382  			Table:   machine.AlertsTable,
   383  			Columns: []string{machine.AlertsColumn},
   384  			Bidi:    false,
   385  			Target: &sqlgraph.EdgeTarget{
   386  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   387  			},
   388  		}
   389  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   390  	}
   391  	if nodes := mu.mutation.RemovedAlertsIDs(); len(nodes) > 0 && !mu.mutation.AlertsCleared() {
   392  		edge := &sqlgraph.EdgeSpec{
   393  			Rel:     sqlgraph.O2M,
   394  			Inverse: false,
   395  			Table:   machine.AlertsTable,
   396  			Columns: []string{machine.AlertsColumn},
   397  			Bidi:    false,
   398  			Target: &sqlgraph.EdgeTarget{
   399  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   400  			},
   401  		}
   402  		for _, k := range nodes {
   403  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   404  		}
   405  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   406  	}
   407  	if nodes := mu.mutation.AlertsIDs(); len(nodes) > 0 {
   408  		edge := &sqlgraph.EdgeSpec{
   409  			Rel:     sqlgraph.O2M,
   410  			Inverse: false,
   411  			Table:   machine.AlertsTable,
   412  			Columns: []string{machine.AlertsColumn},
   413  			Bidi:    false,
   414  			Target: &sqlgraph.EdgeTarget{
   415  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   416  			},
   417  		}
   418  		for _, k := range nodes {
   419  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   420  		}
   421  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   422  	}
   423  	if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil {
   424  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   425  			err = &NotFoundError{machine.Label}
   426  		} else if sqlgraph.IsConstraintError(err) {
   427  			err = &ConstraintError{msg: err.Error(), wrap: err}
   428  		}
   429  		return 0, err
   430  	}
   431  	mu.mutation.done = true
   432  	return n, nil
   433  }
   434  
   435  // MachineUpdateOne is the builder for updating a single Machine entity.
   436  type MachineUpdateOne struct {
   437  	config
   438  	fields   []string
   439  	hooks    []Hook
   440  	mutation *MachineMutation
   441  }
   442  
   443  // SetCreatedAt sets the "created_at" field.
   444  func (muo *MachineUpdateOne) SetCreatedAt(t time.Time) *MachineUpdateOne {
   445  	muo.mutation.SetCreatedAt(t)
   446  	return muo
   447  }
   448  
   449  // ClearCreatedAt clears the value of the "created_at" field.
   450  func (muo *MachineUpdateOne) ClearCreatedAt() *MachineUpdateOne {
   451  	muo.mutation.ClearCreatedAt()
   452  	return muo
   453  }
   454  
   455  // SetUpdatedAt sets the "updated_at" field.
   456  func (muo *MachineUpdateOne) SetUpdatedAt(t time.Time) *MachineUpdateOne {
   457  	muo.mutation.SetUpdatedAt(t)
   458  	return muo
   459  }
   460  
   461  // ClearUpdatedAt clears the value of the "updated_at" field.
   462  func (muo *MachineUpdateOne) ClearUpdatedAt() *MachineUpdateOne {
   463  	muo.mutation.ClearUpdatedAt()
   464  	return muo
   465  }
   466  
   467  // SetLastPush sets the "last_push" field.
   468  func (muo *MachineUpdateOne) SetLastPush(t time.Time) *MachineUpdateOne {
   469  	muo.mutation.SetLastPush(t)
   470  	return muo
   471  }
   472  
   473  // ClearLastPush clears the value of the "last_push" field.
   474  func (muo *MachineUpdateOne) ClearLastPush() *MachineUpdateOne {
   475  	muo.mutation.ClearLastPush()
   476  	return muo
   477  }
   478  
   479  // SetLastHeartbeat sets the "last_heartbeat" field.
   480  func (muo *MachineUpdateOne) SetLastHeartbeat(t time.Time) *MachineUpdateOne {
   481  	muo.mutation.SetLastHeartbeat(t)
   482  	return muo
   483  }
   484  
   485  // ClearLastHeartbeat clears the value of the "last_heartbeat" field.
   486  func (muo *MachineUpdateOne) ClearLastHeartbeat() *MachineUpdateOne {
   487  	muo.mutation.ClearLastHeartbeat()
   488  	return muo
   489  }
   490  
   491  // SetMachineId sets the "machineId" field.
   492  func (muo *MachineUpdateOne) SetMachineId(s string) *MachineUpdateOne {
   493  	muo.mutation.SetMachineId(s)
   494  	return muo
   495  }
   496  
   497  // SetNillableMachineId sets the "machineId" field if the given value is not nil.
   498  func (muo *MachineUpdateOne) SetNillableMachineId(s *string) *MachineUpdateOne {
   499  	if s != nil {
   500  		muo.SetMachineId(*s)
   501  	}
   502  	return muo
   503  }
   504  
   505  // SetPassword sets the "password" field.
   506  func (muo *MachineUpdateOne) SetPassword(s string) *MachineUpdateOne {
   507  	muo.mutation.SetPassword(s)
   508  	return muo
   509  }
   510  
   511  // SetNillablePassword sets the "password" field if the given value is not nil.
   512  func (muo *MachineUpdateOne) SetNillablePassword(s *string) *MachineUpdateOne {
   513  	if s != nil {
   514  		muo.SetPassword(*s)
   515  	}
   516  	return muo
   517  }
   518  
   519  // SetIpAddress sets the "ipAddress" field.
   520  func (muo *MachineUpdateOne) SetIpAddress(s string) *MachineUpdateOne {
   521  	muo.mutation.SetIpAddress(s)
   522  	return muo
   523  }
   524  
   525  // SetNillableIpAddress sets the "ipAddress" field if the given value is not nil.
   526  func (muo *MachineUpdateOne) SetNillableIpAddress(s *string) *MachineUpdateOne {
   527  	if s != nil {
   528  		muo.SetIpAddress(*s)
   529  	}
   530  	return muo
   531  }
   532  
   533  // SetScenarios sets the "scenarios" field.
   534  func (muo *MachineUpdateOne) SetScenarios(s string) *MachineUpdateOne {
   535  	muo.mutation.SetScenarios(s)
   536  	return muo
   537  }
   538  
   539  // SetNillableScenarios sets the "scenarios" field if the given value is not nil.
   540  func (muo *MachineUpdateOne) SetNillableScenarios(s *string) *MachineUpdateOne {
   541  	if s != nil {
   542  		muo.SetScenarios(*s)
   543  	}
   544  	return muo
   545  }
   546  
   547  // ClearScenarios clears the value of the "scenarios" field.
   548  func (muo *MachineUpdateOne) ClearScenarios() *MachineUpdateOne {
   549  	muo.mutation.ClearScenarios()
   550  	return muo
   551  }
   552  
   553  // SetVersion sets the "version" field.
   554  func (muo *MachineUpdateOne) SetVersion(s string) *MachineUpdateOne {
   555  	muo.mutation.SetVersion(s)
   556  	return muo
   557  }
   558  
   559  // SetNillableVersion sets the "version" field if the given value is not nil.
   560  func (muo *MachineUpdateOne) SetNillableVersion(s *string) *MachineUpdateOne {
   561  	if s != nil {
   562  		muo.SetVersion(*s)
   563  	}
   564  	return muo
   565  }
   566  
   567  // ClearVersion clears the value of the "version" field.
   568  func (muo *MachineUpdateOne) ClearVersion() *MachineUpdateOne {
   569  	muo.mutation.ClearVersion()
   570  	return muo
   571  }
   572  
   573  // SetIsValidated sets the "isValidated" field.
   574  func (muo *MachineUpdateOne) SetIsValidated(b bool) *MachineUpdateOne {
   575  	muo.mutation.SetIsValidated(b)
   576  	return muo
   577  }
   578  
   579  // SetNillableIsValidated sets the "isValidated" field if the given value is not nil.
   580  func (muo *MachineUpdateOne) SetNillableIsValidated(b *bool) *MachineUpdateOne {
   581  	if b != nil {
   582  		muo.SetIsValidated(*b)
   583  	}
   584  	return muo
   585  }
   586  
   587  // SetStatus sets the "status" field.
   588  func (muo *MachineUpdateOne) SetStatus(s string) *MachineUpdateOne {
   589  	muo.mutation.SetStatus(s)
   590  	return muo
   591  }
   592  
   593  // SetNillableStatus sets the "status" field if the given value is not nil.
   594  func (muo *MachineUpdateOne) SetNillableStatus(s *string) *MachineUpdateOne {
   595  	if s != nil {
   596  		muo.SetStatus(*s)
   597  	}
   598  	return muo
   599  }
   600  
   601  // ClearStatus clears the value of the "status" field.
   602  func (muo *MachineUpdateOne) ClearStatus() *MachineUpdateOne {
   603  	muo.mutation.ClearStatus()
   604  	return muo
   605  }
   606  
   607  // SetAuthType sets the "auth_type" field.
   608  func (muo *MachineUpdateOne) SetAuthType(s string) *MachineUpdateOne {
   609  	muo.mutation.SetAuthType(s)
   610  	return muo
   611  }
   612  
   613  // SetNillableAuthType sets the "auth_type" field if the given value is not nil.
   614  func (muo *MachineUpdateOne) SetNillableAuthType(s *string) *MachineUpdateOne {
   615  	if s != nil {
   616  		muo.SetAuthType(*s)
   617  	}
   618  	return muo
   619  }
   620  
   621  // AddAlertIDs adds the "alerts" edge to the Alert entity by IDs.
   622  func (muo *MachineUpdateOne) AddAlertIDs(ids ...int) *MachineUpdateOne {
   623  	muo.mutation.AddAlertIDs(ids...)
   624  	return muo
   625  }
   626  
   627  // AddAlerts adds the "alerts" edges to the Alert entity.
   628  func (muo *MachineUpdateOne) AddAlerts(a ...*Alert) *MachineUpdateOne {
   629  	ids := make([]int, len(a))
   630  	for i := range a {
   631  		ids[i] = a[i].ID
   632  	}
   633  	return muo.AddAlertIDs(ids...)
   634  }
   635  
   636  // Mutation returns the MachineMutation object of the builder.
   637  func (muo *MachineUpdateOne) Mutation() *MachineMutation {
   638  	return muo.mutation
   639  }
   640  
   641  // ClearAlerts clears all "alerts" edges to the Alert entity.
   642  func (muo *MachineUpdateOne) ClearAlerts() *MachineUpdateOne {
   643  	muo.mutation.ClearAlerts()
   644  	return muo
   645  }
   646  
   647  // RemoveAlertIDs removes the "alerts" edge to Alert entities by IDs.
   648  func (muo *MachineUpdateOne) RemoveAlertIDs(ids ...int) *MachineUpdateOne {
   649  	muo.mutation.RemoveAlertIDs(ids...)
   650  	return muo
   651  }
   652  
   653  // RemoveAlerts removes "alerts" edges to Alert entities.
   654  func (muo *MachineUpdateOne) RemoveAlerts(a ...*Alert) *MachineUpdateOne {
   655  	ids := make([]int, len(a))
   656  	for i := range a {
   657  		ids[i] = a[i].ID
   658  	}
   659  	return muo.RemoveAlertIDs(ids...)
   660  }
   661  
   662  // Where appends a list predicates to the MachineUpdate builder.
   663  func (muo *MachineUpdateOne) Where(ps ...predicate.Machine) *MachineUpdateOne {
   664  	muo.mutation.Where(ps...)
   665  	return muo
   666  }
   667  
   668  // Select allows selecting one or more fields (columns) of the returned entity.
   669  // The default is selecting all fields defined in the entity schema.
   670  func (muo *MachineUpdateOne) Select(field string, fields ...string) *MachineUpdateOne {
   671  	muo.fields = append([]string{field}, fields...)
   672  	return muo
   673  }
   674  
   675  // Save executes the query and returns the updated Machine entity.
   676  func (muo *MachineUpdateOne) Save(ctx context.Context) (*Machine, error) {
   677  	muo.defaults()
   678  	return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks)
   679  }
   680  
   681  // SaveX is like Save, but panics if an error occurs.
   682  func (muo *MachineUpdateOne) SaveX(ctx context.Context) *Machine {
   683  	node, err := muo.Save(ctx)
   684  	if err != nil {
   685  		panic(err)
   686  	}
   687  	return node
   688  }
   689  
   690  // Exec executes the query on the entity.
   691  func (muo *MachineUpdateOne) Exec(ctx context.Context) error {
   692  	_, err := muo.Save(ctx)
   693  	return err
   694  }
   695  
   696  // ExecX is like Exec, but panics if an error occurs.
   697  func (muo *MachineUpdateOne) ExecX(ctx context.Context) {
   698  	if err := muo.Exec(ctx); err != nil {
   699  		panic(err)
   700  	}
   701  }
   702  
   703  // defaults sets the default values of the builder before save.
   704  func (muo *MachineUpdateOne) defaults() {
   705  	if _, ok := muo.mutation.CreatedAt(); !ok && !muo.mutation.CreatedAtCleared() {
   706  		v := machine.UpdateDefaultCreatedAt()
   707  		muo.mutation.SetCreatedAt(v)
   708  	}
   709  	if _, ok := muo.mutation.UpdatedAt(); !ok && !muo.mutation.UpdatedAtCleared() {
   710  		v := machine.UpdateDefaultUpdatedAt()
   711  		muo.mutation.SetUpdatedAt(v)
   712  	}
   713  	if _, ok := muo.mutation.LastPush(); !ok && !muo.mutation.LastPushCleared() {
   714  		v := machine.UpdateDefaultLastPush()
   715  		muo.mutation.SetLastPush(v)
   716  	}
   717  	if _, ok := muo.mutation.LastHeartbeat(); !ok && !muo.mutation.LastHeartbeatCleared() {
   718  		v := machine.UpdateDefaultLastHeartbeat()
   719  		muo.mutation.SetLastHeartbeat(v)
   720  	}
   721  }
   722  
   723  // check runs all checks and user-defined validators on the builder.
   724  func (muo *MachineUpdateOne) check() error {
   725  	if v, ok := muo.mutation.Scenarios(); ok {
   726  		if err := machine.ScenariosValidator(v); err != nil {
   727  			return &ValidationError{Name: "scenarios", err: fmt.Errorf(`ent: validator failed for field "Machine.scenarios": %w`, err)}
   728  		}
   729  	}
   730  	return nil
   731  }
   732  
   733  func (muo *MachineUpdateOne) sqlSave(ctx context.Context) (_node *Machine, err error) {
   734  	if err := muo.check(); err != nil {
   735  		return _node, err
   736  	}
   737  	_spec := sqlgraph.NewUpdateSpec(machine.Table, machine.Columns, sqlgraph.NewFieldSpec(machine.FieldID, field.TypeInt))
   738  	id, ok := muo.mutation.ID()
   739  	if !ok {
   740  		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Machine.id" for update`)}
   741  	}
   742  	_spec.Node.ID.Value = id
   743  	if fields := muo.fields; len(fields) > 0 {
   744  		_spec.Node.Columns = make([]string, 0, len(fields))
   745  		_spec.Node.Columns = append(_spec.Node.Columns, machine.FieldID)
   746  		for _, f := range fields {
   747  			if !machine.ValidColumn(f) {
   748  				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
   749  			}
   750  			if f != machine.FieldID {
   751  				_spec.Node.Columns = append(_spec.Node.Columns, f)
   752  			}
   753  		}
   754  	}
   755  	if ps := muo.mutation.predicates; len(ps) > 0 {
   756  		_spec.Predicate = func(selector *sql.Selector) {
   757  			for i := range ps {
   758  				ps[i](selector)
   759  			}
   760  		}
   761  	}
   762  	if value, ok := muo.mutation.CreatedAt(); ok {
   763  		_spec.SetField(machine.FieldCreatedAt, field.TypeTime, value)
   764  	}
   765  	if muo.mutation.CreatedAtCleared() {
   766  		_spec.ClearField(machine.FieldCreatedAt, field.TypeTime)
   767  	}
   768  	if value, ok := muo.mutation.UpdatedAt(); ok {
   769  		_spec.SetField(machine.FieldUpdatedAt, field.TypeTime, value)
   770  	}
   771  	if muo.mutation.UpdatedAtCleared() {
   772  		_spec.ClearField(machine.FieldUpdatedAt, field.TypeTime)
   773  	}
   774  	if value, ok := muo.mutation.LastPush(); ok {
   775  		_spec.SetField(machine.FieldLastPush, field.TypeTime, value)
   776  	}
   777  	if muo.mutation.LastPushCleared() {
   778  		_spec.ClearField(machine.FieldLastPush, field.TypeTime)
   779  	}
   780  	if value, ok := muo.mutation.LastHeartbeat(); ok {
   781  		_spec.SetField(machine.FieldLastHeartbeat, field.TypeTime, value)
   782  	}
   783  	if muo.mutation.LastHeartbeatCleared() {
   784  		_spec.ClearField(machine.FieldLastHeartbeat, field.TypeTime)
   785  	}
   786  	if value, ok := muo.mutation.MachineId(); ok {
   787  		_spec.SetField(machine.FieldMachineId, field.TypeString, value)
   788  	}
   789  	if value, ok := muo.mutation.Password(); ok {
   790  		_spec.SetField(machine.FieldPassword, field.TypeString, value)
   791  	}
   792  	if value, ok := muo.mutation.IpAddress(); ok {
   793  		_spec.SetField(machine.FieldIpAddress, field.TypeString, value)
   794  	}
   795  	if value, ok := muo.mutation.Scenarios(); ok {
   796  		_spec.SetField(machine.FieldScenarios, field.TypeString, value)
   797  	}
   798  	if muo.mutation.ScenariosCleared() {
   799  		_spec.ClearField(machine.FieldScenarios, field.TypeString)
   800  	}
   801  	if value, ok := muo.mutation.Version(); ok {
   802  		_spec.SetField(machine.FieldVersion, field.TypeString, value)
   803  	}
   804  	if muo.mutation.VersionCleared() {
   805  		_spec.ClearField(machine.FieldVersion, field.TypeString)
   806  	}
   807  	if value, ok := muo.mutation.IsValidated(); ok {
   808  		_spec.SetField(machine.FieldIsValidated, field.TypeBool, value)
   809  	}
   810  	if value, ok := muo.mutation.Status(); ok {
   811  		_spec.SetField(machine.FieldStatus, field.TypeString, value)
   812  	}
   813  	if muo.mutation.StatusCleared() {
   814  		_spec.ClearField(machine.FieldStatus, field.TypeString)
   815  	}
   816  	if value, ok := muo.mutation.AuthType(); ok {
   817  		_spec.SetField(machine.FieldAuthType, field.TypeString, value)
   818  	}
   819  	if muo.mutation.AlertsCleared() {
   820  		edge := &sqlgraph.EdgeSpec{
   821  			Rel:     sqlgraph.O2M,
   822  			Inverse: false,
   823  			Table:   machine.AlertsTable,
   824  			Columns: []string{machine.AlertsColumn},
   825  			Bidi:    false,
   826  			Target: &sqlgraph.EdgeTarget{
   827  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   828  			},
   829  		}
   830  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   831  	}
   832  	if nodes := muo.mutation.RemovedAlertsIDs(); len(nodes) > 0 && !muo.mutation.AlertsCleared() {
   833  		edge := &sqlgraph.EdgeSpec{
   834  			Rel:     sqlgraph.O2M,
   835  			Inverse: false,
   836  			Table:   machine.AlertsTable,
   837  			Columns: []string{machine.AlertsColumn},
   838  			Bidi:    false,
   839  			Target: &sqlgraph.EdgeTarget{
   840  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   841  			},
   842  		}
   843  		for _, k := range nodes {
   844  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   845  		}
   846  		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
   847  	}
   848  	if nodes := muo.mutation.AlertsIDs(); len(nodes) > 0 {
   849  		edge := &sqlgraph.EdgeSpec{
   850  			Rel:     sqlgraph.O2M,
   851  			Inverse: false,
   852  			Table:   machine.AlertsTable,
   853  			Columns: []string{machine.AlertsColumn},
   854  			Bidi:    false,
   855  			Target: &sqlgraph.EdgeTarget{
   856  				IDSpec: sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt),
   857  			},
   858  		}
   859  		for _, k := range nodes {
   860  			edge.Target.Nodes = append(edge.Target.Nodes, k)
   861  		}
   862  		_spec.Edges.Add = append(_spec.Edges.Add, edge)
   863  	}
   864  	_node = &Machine{config: muo.config}
   865  	_spec.Assign = _node.assignValues
   866  	_spec.ScanValues = _node.scanValues
   867  	if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
   868  		if _, ok := err.(*sqlgraph.NotFoundError); ok {
   869  			err = &NotFoundError{machine.Label}
   870  		} else if sqlgraph.IsConstraintError(err) {
   871  			err = &ConstraintError{msg: err.Error(), wrap: err}
   872  		}
   873  		return nil, err
   874  	}
   875  	muo.mutation.done = true
   876  	return _node, nil
   877  }