From 42a57e0a5fb35daa695a7a6c2143f3ef4bb53a21 Mon Sep 17 00:00:00 2001 From: alteredCoder Date: Tue, 26 Oct 2021 15:50:24 +0200 Subject: [PATCH] update schema --- pkg/database/ent/machine/where.go | 14 ++++++++++++++ pkg/database/ent/machine_create.go | 3 --- pkg/database/ent/machine_update.go | 24 ++++++++++++++++++++++++ pkg/database/ent/migrate/schema.go | 2 +- pkg/database/ent/mutation.go | 19 +++++++++++++++++++ pkg/database/ent/schema/machine.go | 2 +- 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/pkg/database/ent/machine/where.go b/pkg/database/ent/machine/where.go index c4a05d0b7..abfe05a81 100644 --- a/pkg/database/ent/machine/where.go +++ b/pkg/database/ent/machine/where.go @@ -391,6 +391,20 @@ func LastPushLTE(v time.Time) predicate.Machine { }) } +// LastPushIsNil applies the IsNil predicate on the "last_push" field. +func LastPushIsNil() predicate.Machine { + return predicate.Machine(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldLastPush))) + }) +} + +// LastPushNotNil applies the NotNil predicate on the "last_push" field. +func LastPushNotNil() predicate.Machine { + return predicate.Machine(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldLastPush))) + }) +} + // MachineIdEQ applies the EQ predicate on the "machineId" field. func MachineIdEQ(v string) predicate.Machine { return predicate.Machine(func(s *sql.Selector) { diff --git a/pkg/database/ent/machine_create.go b/pkg/database/ent/machine_create.go index 33925b389..1c1508850 100644 --- a/pkg/database/ent/machine_create.go +++ b/pkg/database/ent/machine_create.go @@ -249,9 +249,6 @@ func (mc *MachineCreate) check() error { if _, ok := mc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "updated_at"`)} } - if _, ok := mc.mutation.LastPush(); !ok { - return &ValidationError{Name: "last_push", err: errors.New("ent: missing required field \"last_push\"")} - } if _, ok := mc.mutation.MachineId(); !ok { return &ValidationError{Name: "machineId", err: errors.New(`ent: missing required field "machineId"`)} } diff --git a/pkg/database/ent/machine_update.go b/pkg/database/ent/machine_update.go index 54113d4b9..5242897c9 100644 --- a/pkg/database/ent/machine_update.go +++ b/pkg/database/ent/machine_update.go @@ -70,6 +70,12 @@ func (mu *MachineUpdate) SetNillableLastPush(t *time.Time) *MachineUpdate { return mu } +// ClearLastPush clears the value of the "last_push" field. +func (mu *MachineUpdate) ClearLastPush() *MachineUpdate { + mu.mutation.ClearLastPush() + return mu +} + // SetMachineId sets the "machineId" field. func (mu *MachineUpdate) SetMachineId(s string) *MachineUpdate { mu.mutation.SetMachineId(s) @@ -312,6 +318,12 @@ func (mu *MachineUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: machine.FieldLastPush, }) } + if mu.mutation.LastPushCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: machine.FieldLastPush, + }) + } if value, ok := mu.mutation.MachineId(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, @@ -494,6 +506,12 @@ func (muo *MachineUpdateOne) SetNillableLastPush(t *time.Time) *MachineUpdateOne return muo } +// ClearLastPush clears the value of the "last_push" field. +func (muo *MachineUpdateOne) ClearLastPush() *MachineUpdateOne { + muo.mutation.ClearLastPush() + return muo +} + // SetMachineId sets the "machineId" field. func (muo *MachineUpdateOne) SetMachineId(s string) *MachineUpdateOne { muo.mutation.SetMachineId(s) @@ -760,6 +778,12 @@ func (muo *MachineUpdateOne) sqlSave(ctx context.Context) (_node *Machine, err e Column: machine.FieldLastPush, }) } + if muo.mutation.LastPushCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: machine.FieldLastPush, + }) + } if value, ok := muo.mutation.MachineId(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, diff --git a/pkg/database/ent/migrate/schema.go b/pkg/database/ent/migrate/schema.go index 5355909b9..c70400612 100644 --- a/pkg/database/ent/migrate/schema.go +++ b/pkg/database/ent/migrate/schema.go @@ -137,7 +137,7 @@ var ( {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, - {Name: "last_push", Type: field.TypeTime}, + {Name: "last_push", Type: field.TypeTime, Nullable: true}, {Name: "machine_id", Type: field.TypeString, Unique: true}, {Name: "password", Type: field.TypeString}, {Name: "ip_address", Type: field.TypeString}, diff --git a/pkg/database/ent/mutation.go b/pkg/database/ent/mutation.go index 7966db171..1bb87c802 100644 --- a/pkg/database/ent/mutation.go +++ b/pkg/database/ent/mutation.go @@ -5185,9 +5185,22 @@ func (m *MachineMutation) OldLastPush(ctx context.Context) (v time.Time, err err return oldValue.LastPush, nil } +// ClearLastPush clears the value of the "last_push" field. +func (m *MachineMutation) ClearLastPush() { + m.last_push = nil + m.clearedFields[machine.FieldLastPush] = struct{}{} +} + +// LastPushCleared returns if the "last_push" field was cleared in this mutation. +func (m *MachineMutation) LastPushCleared() bool { + _, ok := m.clearedFields[machine.FieldLastPush] + return ok +} + // ResetLastPush resets all changes to the "last_push" field. func (m *MachineMutation) ResetLastPush() { m.last_push = nil + delete(m.clearedFields, machine.FieldLastPush) } // SetMachineId sets the "machineId" field. @@ -5751,6 +5764,9 @@ func (m *MachineMutation) AddField(name string, value ent.Value) error { // mutation. func (m *MachineMutation) ClearedFields() []string { var fields []string + if m.FieldCleared(machine.FieldLastPush) { + fields = append(fields, machine.FieldLastPush) + } if m.FieldCleared(machine.FieldScenarios) { fields = append(fields, machine.FieldScenarios) } @@ -5774,6 +5790,9 @@ func (m *MachineMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *MachineMutation) ClearField(name string) error { switch name { + case machine.FieldLastPush: + m.ClearLastPush() + return nil case machine.FieldScenarios: m.ClearScenarios() return nil diff --git a/pkg/database/ent/schema/machine.go b/pkg/database/ent/schema/machine.go index f301613c7..e81529974 100644 --- a/pkg/database/ent/schema/machine.go +++ b/pkg/database/ent/schema/machine.go @@ -21,7 +21,7 @@ func (Machine) Fields() []ent.Field { field.Time("updated_at"). Default(time.Now), field.Time("last_push"). - Default(time.Now), + Default(time.Now).Optional(), field.String("machineId").Unique(), field.String("password").Sensitive(), field.String("ipAddress"),