update machine schema to have last_push field

This commit is contained in:
bui 2021-10-08 15:48:36 +02:00 committed by alteredCoder
parent 5d6422b8fa
commit 50a065dc5d
9 changed files with 234 additions and 4 deletions

View file

@ -20,6 +20,8 @@ type Machine struct {
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// LastPush holds the value of the "last_push" field.
LastPush time.Time `json:"last_push,omitempty"`
// MachineId holds the value of the "machineId" field.
MachineId string `json:"machineId,omitempty"`
// Password holds the value of the "password" field.
@ -68,7 +70,7 @@ func (*Machine) scanValues(columns []string) ([]interface{}, error) {
values[i] = new(sql.NullInt64)
case machine.FieldMachineId, machine.FieldPassword, machine.FieldIpAddress, machine.FieldScenarios, machine.FieldVersion, machine.FieldStatus:
values[i] = new(sql.NullString)
case machine.FieldCreatedAt, machine.FieldUpdatedAt:
case machine.FieldCreatedAt, machine.FieldUpdatedAt, machine.FieldLastPush:
values[i] = new(sql.NullTime)
default:
return nil, fmt.Errorf("unexpected column %q for type Machine", columns[i])
@ -103,6 +105,12 @@ func (m *Machine) assignValues(columns []string, values []interface{}) error {
} else if value.Valid {
m.UpdatedAt = value.Time
}
case machine.FieldLastPush:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_push", values[i])
} else if value.Valid {
m.LastPush = value.Time
}
case machine.FieldMachineId:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field machineId", values[i])
@ -182,6 +190,8 @@ func (m *Machine) String() string {
builder.WriteString(m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", updated_at=")
builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", last_push=")
builder.WriteString(m.LastPush.Format(time.ANSIC))
builder.WriteString(", machineId=")
builder.WriteString(m.MachineId)
builder.WriteString(", password=<sensitive>")

View file

@ -15,6 +15,8 @@ const (
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldLastPush holds the string denoting the last_push field in the database.
FieldLastPush = "last_push"
// FieldMachineId holds the string denoting the machineid field in the database.
FieldMachineId = "machine_id"
// FieldPassword holds the string denoting the password field in the database.
@ -47,6 +49,7 @@ var Columns = []string{
FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldLastPush,
FieldMachineId,
FieldPassword,
FieldIpAddress,
@ -71,6 +74,8 @@ var (
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// DefaultLastPush holds the default value on creation for the "last_push" field.
DefaultLastPush func() time.Time
// ScenariosValidator is a validator for the "scenarios" field. It is called by the builders before save.
ScenariosValidator func(string) error
// DefaultIsValidated holds the default value on creation for the "isValidated" field.

View file

@ -107,6 +107,13 @@ func UpdatedAt(v time.Time) predicate.Machine {
})
}
// LastPush applies equality check predicate on the "last_push" field. It's identical to LastPushEQ.
func LastPush(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldLastPush), v))
})
}
// MachineId applies equality check predicate on the "machineId" field. It's identical to MachineIdEQ.
func MachineId(v string) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
@ -308,6 +315,82 @@ func UpdatedAtLTE(v time.Time) predicate.Machine {
})
}
// LastPushEQ applies the EQ predicate on the "last_push" field.
func LastPushEQ(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldLastPush), v))
})
}
// LastPushNEQ applies the NEQ predicate on the "last_push" field.
func LastPushNEQ(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldLastPush), v))
})
}
// LastPushIn applies the In predicate on the "last_push" field.
func LastPushIn(vs ...time.Time) predicate.Machine {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Machine(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldLastPush), v...))
})
}
// LastPushNotIn applies the NotIn predicate on the "last_push" field.
func LastPushNotIn(vs ...time.Time) predicate.Machine {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.Machine(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldLastPush), v...))
})
}
// LastPushGT applies the GT predicate on the "last_push" field.
func LastPushGT(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldLastPush), v))
})
}
// LastPushGTE applies the GTE predicate on the "last_push" field.
func LastPushGTE(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldLastPush), v))
})
}
// LastPushLT applies the LT predicate on the "last_push" field.
func LastPushLT(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldLastPush), v))
})
}
// LastPushLTE applies the LTE predicate on the "last_push" field.
func LastPushLTE(v time.Time) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldLastPush), v))
})
}
// MachineIdEQ applies the EQ predicate on the "machineId" field.
func MachineIdEQ(v string) predicate.Machine {
return predicate.Machine(func(s *sql.Selector) {

View file

@ -49,6 +49,20 @@ func (mc *MachineCreate) SetNillableUpdatedAt(t *time.Time) *MachineCreate {
return mc
}
// SetLastPush sets the "last_push" field.
func (mc *MachineCreate) SetLastPush(t time.Time) *MachineCreate {
mc.mutation.SetLastPush(t)
return mc
}
// SetNillableLastPush sets the "last_push" field if the given value is not nil.
func (mc *MachineCreate) SetNillableLastPush(t *time.Time) *MachineCreate {
if t != nil {
mc.SetLastPush(*t)
}
return mc
}
// SetMachineId sets the "machineId" field.
func (mc *MachineCreate) SetMachineId(s string) *MachineCreate {
mc.mutation.SetMachineId(s)
@ -217,6 +231,10 @@ func (mc *MachineCreate) defaults() {
v := machine.DefaultUpdatedAt()
mc.mutation.SetUpdatedAt(v)
}
if _, ok := mc.mutation.LastPush(); !ok {
v := machine.DefaultLastPush()
mc.mutation.SetLastPush(v)
}
if _, ok := mc.mutation.IsValidated(); !ok {
v := machine.DefaultIsValidated
mc.mutation.SetIsValidated(v)
@ -231,6 +249,9 @@ 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"`)}
}
@ -291,6 +312,14 @@ func (mc *MachineCreate) createSpec() (*Machine, *sqlgraph.CreateSpec) {
})
_node.UpdatedAt = value
}
if value, ok := mc.mutation.LastPush(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: machine.FieldLastPush,
})
_node.LastPush = value
}
if value, ok := mc.mutation.MachineId(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,

View file

@ -56,6 +56,20 @@ func (mu *MachineUpdate) SetNillableUpdatedAt(t *time.Time) *MachineUpdate {
return mu
}
// SetLastPush sets the "last_push" field.
func (mu *MachineUpdate) SetLastPush(t time.Time) *MachineUpdate {
mu.mutation.SetLastPush(t)
return mu
}
// SetNillableLastPush sets the "last_push" field if the given value is not nil.
func (mu *MachineUpdate) SetNillableLastPush(t *time.Time) *MachineUpdate {
if t != nil {
mu.SetLastPush(*t)
}
return mu
}
// SetMachineId sets the "machineId" field.
func (mu *MachineUpdate) SetMachineId(s string) *MachineUpdate {
mu.mutation.SetMachineId(s)
@ -291,6 +305,13 @@ func (mu *MachineUpdate) sqlSave(ctx context.Context) (n int, err error) {
Column: machine.FieldUpdatedAt,
})
}
if value, ok := mu.mutation.LastPush(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: machine.FieldLastPush,
})
}
if value, ok := mu.mutation.MachineId(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
@ -459,6 +480,20 @@ func (muo *MachineUpdateOne) SetNillableUpdatedAt(t *time.Time) *MachineUpdateOn
return muo
}
// SetLastPush sets the "last_push" field.
func (muo *MachineUpdateOne) SetLastPush(t time.Time) *MachineUpdateOne {
muo.mutation.SetLastPush(t)
return muo
}
// SetNillableLastPush sets the "last_push" field if the given value is not nil.
func (muo *MachineUpdateOne) SetNillableLastPush(t *time.Time) *MachineUpdateOne {
if t != nil {
muo.SetLastPush(*t)
}
return muo
}
// SetMachineId sets the "machineId" field.
func (muo *MachineUpdateOne) SetMachineId(s string) *MachineUpdateOne {
muo.mutation.SetMachineId(s)
@ -718,6 +753,13 @@ func (muo *MachineUpdateOne) sqlSave(ctx context.Context) (_node *Machine, err e
Column: machine.FieldUpdatedAt,
})
}
if value, ok := muo.mutation.LastPush(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: machine.FieldLastPush,
})
}
if value, ok := muo.mutation.MachineId(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,

View file

@ -137,6 +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: "machine_id", Type: field.TypeString, Unique: true},
{Name: "password", Type: field.TypeString},
{Name: "ip_address", Type: field.TypeString},

View file

@ -4986,6 +4986,7 @@ type MachineMutation struct {
id *int
created_at *time.Time
updated_at *time.Time
last_push *time.Time
machineId *string
password *string
ipAddress *string
@ -5153,6 +5154,42 @@ func (m *MachineMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetLastPush sets the "last_push" field.
func (m *MachineMutation) SetLastPush(t time.Time) {
m.last_push = &t
}
// LastPush returns the value of the "last_push" field in the mutation.
func (m *MachineMutation) LastPush() (r time.Time, exists bool) {
v := m.last_push
if v == nil {
return
}
return *v, true
}
// OldLastPush returns the old "last_push" field's value of the Machine entity.
// If the Machine object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MachineMutation) OldLastPush(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldLastPush is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldLastPush requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLastPush: %w", err)
}
return oldValue.LastPush, nil
}
// ResetLastPush resets all changes to the "last_push" field.
func (m *MachineMutation) ResetLastPush() {
m.last_push = nil
}
// SetMachineId sets the "machineId" field.
func (m *MachineMutation) SetMachineId(s string) {
m.machineId = &s
@ -5517,13 +5554,16 @@ func (m *MachineMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *MachineMutation) Fields() []string {
fields := make([]string, 0, 9)
fields := make([]string, 0, 10)
if m.created_at != nil {
fields = append(fields, machine.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, machine.FieldUpdatedAt)
}
if m.last_push != nil {
fields = append(fields, machine.FieldLastPush)
}
if m.machineId != nil {
fields = append(fields, machine.FieldMachineId)
}
@ -5557,6 +5597,8 @@ func (m *MachineMutation) Field(name string) (ent.Value, bool) {
return m.CreatedAt()
case machine.FieldUpdatedAt:
return m.UpdatedAt()
case machine.FieldLastPush:
return m.LastPush()
case machine.FieldMachineId:
return m.MachineId()
case machine.FieldPassword:
@ -5584,6 +5626,8 @@ func (m *MachineMutation) OldField(ctx context.Context, name string) (ent.Value,
return m.OldCreatedAt(ctx)
case machine.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case machine.FieldLastPush:
return m.OldLastPush(ctx)
case machine.FieldMachineId:
return m.OldMachineId(ctx)
case machine.FieldPassword:
@ -5621,6 +5665,13 @@ func (m *MachineMutation) SetField(name string, value ent.Value) error {
}
m.SetUpdatedAt(v)
return nil
case machine.FieldLastPush:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLastPush(v)
return nil
case machine.FieldMachineId:
v, ok := value.(string)
if !ok {
@ -5746,6 +5797,9 @@ func (m *MachineMutation) ResetField(name string) error {
case machine.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case machine.FieldLastPush:
m.ResetLastPush()
return nil
case machine.FieldMachineId:
m.ResetMachineId()
return nil

View file

@ -112,12 +112,16 @@ func init() {
machineDescUpdatedAt := machineFields[1].Descriptor()
// machine.DefaultUpdatedAt holds the default value on creation for the updated_at field.
machine.DefaultUpdatedAt = machineDescUpdatedAt.Default.(func() time.Time)
// machineDescLastPush is the schema descriptor for last_push field.
machineDescLastPush := machineFields[2].Descriptor()
// machine.DefaultLastPush holds the default value on creation for the last_push field.
machine.DefaultLastPush = machineDescLastPush.Default.(func() time.Time)
// machineDescScenarios is the schema descriptor for scenarios field.
machineDescScenarios := machineFields[5].Descriptor()
machineDescScenarios := machineFields[6].Descriptor()
// machine.ScenariosValidator is a validator for the "scenarios" field. It is called by the builders before save.
machine.ScenariosValidator = machineDescScenarios.Validators[0].(func(string) error)
// machineDescIsValidated is the schema descriptor for isValidated field.
machineDescIsValidated := machineFields[7].Descriptor()
machineDescIsValidated := machineFields[8].Descriptor()
// machine.DefaultIsValidated holds the default value on creation for the isValidated field.
machine.DefaultIsValidated = machineDescIsValidated.Default.(bool)
metaFields := schema.Meta{}.Fields()

View file

@ -20,6 +20,8 @@ func (Machine) Fields() []ent.Field {
Default(time.Now),
field.Time("updated_at").
Default(time.Now),
field.Time("last_push").
Default(time.Now),
field.String("machineId").Unique(),
field.String("password").Sensitive(),
field.String("ipAddress"),