diff --git a/internal/ent/migrate/schema.go b/internal/ent/migrate/schema.go index 0eddfce..5b8a660 100644 --- a/internal/ent/migrate/schema.go +++ b/internal/ent/migrate/schema.go @@ -45,11 +45,11 @@ var ( // TelegramAccountsColumns holds the columns for the "telegram_accounts" table. TelegramAccountsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString}, - {Name: "code", Type: field.TypeString}, - {Name: "code_at", Type: field.TypeTime}, + {Name: "code", Type: field.TypeString, Nullable: true}, + {Name: "code_at", Type: field.TypeTime, Nullable: true}, {Name: "state", Type: field.TypeEnum, Enums: []string{"New", "CodeSent", "Active", "Error"}, Default: "New"}, {Name: "status", Type: field.TypeString}, - {Name: "session", Type: field.TypeBytes}, + {Name: "session", Type: field.TypeBytes, Nullable: true}, } // TelegramAccountsTable holds the schema information for the "telegram_accounts" table. TelegramAccountsTable = &schema.Table{ diff --git a/internal/ent/mutation.go b/internal/ent/mutation.go index f93a909..86cf2bb 100644 --- a/internal/ent/mutation.go +++ b/internal/ent/mutation.go @@ -1242,7 +1242,7 @@ func (m *TelegramAccountMutation) Code() (r string, exists bool) { // OldCode returns the old "code" field's value of the TelegramAccount entity. // If the TelegramAccount 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 *TelegramAccountMutation) OldCode(ctx context.Context) (v string, err error) { +func (m *TelegramAccountMutation) OldCode(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCode is only allowed on UpdateOne operations") } @@ -1256,9 +1256,22 @@ func (m *TelegramAccountMutation) OldCode(ctx context.Context) (v string, err er return oldValue.Code, nil } +// ClearCode clears the value of the "code" field. +func (m *TelegramAccountMutation) ClearCode() { + m.code = nil + m.clearedFields[telegramaccount.FieldCode] = struct{}{} +} + +// CodeCleared returns if the "code" field was cleared in this mutation. +func (m *TelegramAccountMutation) CodeCleared() bool { + _, ok := m.clearedFields[telegramaccount.FieldCode] + return ok +} + // ResetCode resets all changes to the "code" field. func (m *TelegramAccountMutation) ResetCode() { m.code = nil + delete(m.clearedFields, telegramaccount.FieldCode) } // SetCodeAt sets the "code_at" field. @@ -1278,7 +1291,7 @@ func (m *TelegramAccountMutation) CodeAt() (r time.Time, exists bool) { // OldCodeAt returns the old "code_at" field's value of the TelegramAccount entity. // If the TelegramAccount 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 *TelegramAccountMutation) OldCodeAt(ctx context.Context) (v time.Time, err error) { +func (m *TelegramAccountMutation) OldCodeAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCodeAt is only allowed on UpdateOne operations") } @@ -1292,9 +1305,22 @@ func (m *TelegramAccountMutation) OldCodeAt(ctx context.Context) (v time.Time, e return oldValue.CodeAt, nil } +// ClearCodeAt clears the value of the "code_at" field. +func (m *TelegramAccountMutation) ClearCodeAt() { + m.code_at = nil + m.clearedFields[telegramaccount.FieldCodeAt] = struct{}{} +} + +// CodeAtCleared returns if the "code_at" field was cleared in this mutation. +func (m *TelegramAccountMutation) CodeAtCleared() bool { + _, ok := m.clearedFields[telegramaccount.FieldCodeAt] + return ok +} + // ResetCodeAt resets all changes to the "code_at" field. func (m *TelegramAccountMutation) ResetCodeAt() { m.code_at = nil + delete(m.clearedFields, telegramaccount.FieldCodeAt) } // SetState sets the "state" field. @@ -1400,9 +1426,22 @@ func (m *TelegramAccountMutation) OldSession(ctx context.Context) (v *[]byte, er return oldValue.Session, nil } +// ClearSession clears the value of the "session" field. +func (m *TelegramAccountMutation) ClearSession() { + m.session = nil + m.clearedFields[telegramaccount.FieldSession] = struct{}{} +} + +// SessionCleared returns if the "session" field was cleared in this mutation. +func (m *TelegramAccountMutation) SessionCleared() bool { + _, ok := m.clearedFields[telegramaccount.FieldSession] + return ok +} + // ResetSession resets all changes to the "session" field. func (m *TelegramAccountMutation) ResetSession() { m.session = nil + delete(m.clearedFields, telegramaccount.FieldSession) } // Where appends a list predicates to the TelegramAccountMutation builder. @@ -1565,7 +1604,17 @@ func (m *TelegramAccountMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TelegramAccountMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(telegramaccount.FieldCode) { + fields = append(fields, telegramaccount.FieldCode) + } + if m.FieldCleared(telegramaccount.FieldCodeAt) { + fields = append(fields, telegramaccount.FieldCodeAt) + } + if m.FieldCleared(telegramaccount.FieldSession) { + fields = append(fields, telegramaccount.FieldSession) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was @@ -1578,6 +1627,17 @@ func (m *TelegramAccountMutation) FieldCleared(name string) bool { // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *TelegramAccountMutation) ClearField(name string) error { + switch name { + case telegramaccount.FieldCode: + m.ClearCode() + return nil + case telegramaccount.FieldCodeAt: + m.ClearCodeAt() + return nil + case telegramaccount.FieldSession: + m.ClearSession() + return nil + } return fmt.Errorf("unknown TelegramAccount nullable field %s", name) } diff --git a/internal/ent/schema/telegram_account.go b/internal/ent/schema/telegram_account.go index b76a0f2..0f03493 100644 --- a/internal/ent/schema/telegram_account.go +++ b/internal/ent/schema/telegram_account.go @@ -12,12 +12,18 @@ type TelegramAccount struct { func (TelegramAccount) Fields() []ent.Field { return []ent.Field{ field.String("id").Comment("Phone number without +"), - field.String("code"), - field.Time("code_at"), + field.String("code"). + Optional(). + Nillable(), + field.Time("code_at"). + Optional(). + Nillable(), field.Enum("state"). Values("New", "CodeSent", "Active", "Error").Default("New"), field.String("status"), - field.Bytes("session").Nillable(), + field.Bytes("session"). + Optional(). + Nillable(), } } diff --git a/internal/ent/telegramaccount.go b/internal/ent/telegramaccount.go index 8a0e26c..61c255e 100644 --- a/internal/ent/telegramaccount.go +++ b/internal/ent/telegramaccount.go @@ -19,9 +19,9 @@ type TelegramAccount struct { // Phone number without + ID string `json:"id,omitempty"` // Code holds the value of the "code" field. - Code string `json:"code,omitempty"` + Code *string `json:"code,omitempty"` // CodeAt holds the value of the "code_at" field. - CodeAt time.Time `json:"code_at,omitempty"` + CodeAt *time.Time `json:"code_at,omitempty"` // State holds the value of the "state" field. State telegramaccount.State `json:"state,omitempty"` // Status holds the value of the "status" field. @@ -67,13 +67,15 @@ func (ta *TelegramAccount) assignValues(columns []string, values []any) error { if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field code", values[i]) } else if value.Valid { - ta.Code = value.String + ta.Code = new(string) + *ta.Code = value.String } case telegramaccount.FieldCodeAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field code_at", values[i]) } else if value.Valid { - ta.CodeAt = value.Time + ta.CodeAt = new(time.Time) + *ta.CodeAt = value.Time } case telegramaccount.FieldState: if value, ok := values[i].(*sql.NullString); !ok { @@ -129,11 +131,15 @@ func (ta *TelegramAccount) String() string { var builder strings.Builder builder.WriteString("TelegramAccount(") builder.WriteString(fmt.Sprintf("id=%v, ", ta.ID)) - builder.WriteString("code=") - builder.WriteString(ta.Code) + if v := ta.Code; v != nil { + builder.WriteString("code=") + builder.WriteString(*v) + } builder.WriteString(", ") - builder.WriteString("code_at=") - builder.WriteString(ta.CodeAt.Format(time.ANSIC)) + if v := ta.CodeAt; v != nil { + builder.WriteString("code_at=") + builder.WriteString(v.Format(time.ANSIC)) + } builder.WriteString(", ") builder.WriteString("state=") builder.WriteString(fmt.Sprintf("%v", ta.State)) diff --git a/internal/ent/telegramaccount/where.go b/internal/ent/telegramaccount/where.go index 3b61504..09b3cb5 100644 --- a/internal/ent/telegramaccount/where.go +++ b/internal/ent/telegramaccount/where.go @@ -139,6 +139,16 @@ func CodeHasSuffix(v string) predicate.TelegramAccount { return predicate.TelegramAccount(sql.FieldHasSuffix(FieldCode, v)) } +// CodeIsNil applies the IsNil predicate on the "code" field. +func CodeIsNil() predicate.TelegramAccount { + return predicate.TelegramAccount(sql.FieldIsNull(FieldCode)) +} + +// CodeNotNil applies the NotNil predicate on the "code" field. +func CodeNotNil() predicate.TelegramAccount { + return predicate.TelegramAccount(sql.FieldNotNull(FieldCode)) +} + // CodeEqualFold applies the EqualFold predicate on the "code" field. func CodeEqualFold(v string) predicate.TelegramAccount { return predicate.TelegramAccount(sql.FieldEqualFold(FieldCode, v)) @@ -189,6 +199,16 @@ func CodeAtLTE(v time.Time) predicate.TelegramAccount { return predicate.TelegramAccount(sql.FieldLTE(FieldCodeAt, v)) } +// CodeAtIsNil applies the IsNil predicate on the "code_at" field. +func CodeAtIsNil() predicate.TelegramAccount { + return predicate.TelegramAccount(sql.FieldIsNull(FieldCodeAt)) +} + +// CodeAtNotNil applies the NotNil predicate on the "code_at" field. +func CodeAtNotNil() predicate.TelegramAccount { + return predicate.TelegramAccount(sql.FieldNotNull(FieldCodeAt)) +} + // StateEQ applies the EQ predicate on the "state" field. func StateEQ(v State) predicate.TelegramAccount { return predicate.TelegramAccount(sql.FieldEQ(FieldState, v)) @@ -314,6 +334,16 @@ func SessionLTE(v []byte) predicate.TelegramAccount { return predicate.TelegramAccount(sql.FieldLTE(FieldSession, v)) } +// SessionIsNil applies the IsNil predicate on the "session" field. +func SessionIsNil() predicate.TelegramAccount { + return predicate.TelegramAccount(sql.FieldIsNull(FieldSession)) +} + +// SessionNotNil applies the NotNil predicate on the "session" field. +func SessionNotNil() predicate.TelegramAccount { + return predicate.TelegramAccount(sql.FieldNotNull(FieldSession)) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.TelegramAccount) predicate.TelegramAccount { return predicate.TelegramAccount(sql.AndPredicates(predicates...)) diff --git a/internal/ent/telegramaccount_create.go b/internal/ent/telegramaccount_create.go index eae71f8..06f32a8 100644 --- a/internal/ent/telegramaccount_create.go +++ b/internal/ent/telegramaccount_create.go @@ -29,12 +29,28 @@ func (tac *TelegramAccountCreate) SetCode(s string) *TelegramAccountCreate { return tac } +// SetNillableCode sets the "code" field if the given value is not nil. +func (tac *TelegramAccountCreate) SetNillableCode(s *string) *TelegramAccountCreate { + if s != nil { + tac.SetCode(*s) + } + return tac +} + // SetCodeAt sets the "code_at" field. func (tac *TelegramAccountCreate) SetCodeAt(t time.Time) *TelegramAccountCreate { tac.mutation.SetCodeAt(t) return tac } +// SetNillableCodeAt sets the "code_at" field if the given value is not nil. +func (tac *TelegramAccountCreate) SetNillableCodeAt(t *time.Time) *TelegramAccountCreate { + if t != nil { + tac.SetCodeAt(*t) + } + return tac +} + // SetState sets the "state" field. func (tac *TelegramAccountCreate) SetState(t telegramaccount.State) *TelegramAccountCreate { tac.mutation.SetState(t) @@ -110,12 +126,6 @@ func (tac *TelegramAccountCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (tac *TelegramAccountCreate) check() error { - if _, ok := tac.mutation.Code(); !ok { - return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "TelegramAccount.code"`)} - } - if _, ok := tac.mutation.CodeAt(); !ok { - return &ValidationError{Name: "code_at", err: errors.New(`ent: missing required field "TelegramAccount.code_at"`)} - } if _, ok := tac.mutation.State(); !ok { return &ValidationError{Name: "state", err: errors.New(`ent: missing required field "TelegramAccount.state"`)} } @@ -127,9 +137,6 @@ func (tac *TelegramAccountCreate) check() error { if _, ok := tac.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "TelegramAccount.status"`)} } - if _, ok := tac.mutation.Session(); !ok { - return &ValidationError{Name: "session", err: errors.New(`ent: missing required field "TelegramAccount.session"`)} - } return nil } @@ -168,11 +175,11 @@ func (tac *TelegramAccountCreate) createSpec() (*TelegramAccount, *sqlgraph.Crea } if value, ok := tac.mutation.Code(); ok { _spec.SetField(telegramaccount.FieldCode, field.TypeString, value) - _node.Code = value + _node.Code = &value } if value, ok := tac.mutation.CodeAt(); ok { _spec.SetField(telegramaccount.FieldCodeAt, field.TypeTime, value) - _node.CodeAt = value + _node.CodeAt = &value } if value, ok := tac.mutation.State(); ok { _spec.SetField(telegramaccount.FieldState, field.TypeEnum, value) @@ -250,6 +257,12 @@ func (u *TelegramAccountUpsert) UpdateCode() *TelegramAccountUpsert { return u } +// ClearCode clears the value of the "code" field. +func (u *TelegramAccountUpsert) ClearCode() *TelegramAccountUpsert { + u.SetNull(telegramaccount.FieldCode) + return u +} + // SetCodeAt sets the "code_at" field. func (u *TelegramAccountUpsert) SetCodeAt(v time.Time) *TelegramAccountUpsert { u.Set(telegramaccount.FieldCodeAt, v) @@ -262,6 +275,12 @@ func (u *TelegramAccountUpsert) UpdateCodeAt() *TelegramAccountUpsert { return u } +// ClearCodeAt clears the value of the "code_at" field. +func (u *TelegramAccountUpsert) ClearCodeAt() *TelegramAccountUpsert { + u.SetNull(telegramaccount.FieldCodeAt) + return u +} + // SetState sets the "state" field. func (u *TelegramAccountUpsert) SetState(v telegramaccount.State) *TelegramAccountUpsert { u.Set(telegramaccount.FieldState, v) @@ -298,6 +317,12 @@ func (u *TelegramAccountUpsert) UpdateSession() *TelegramAccountUpsert { return u } +// ClearSession clears the value of the "session" field. +func (u *TelegramAccountUpsert) ClearSession() *TelegramAccountUpsert { + u.SetNull(telegramaccount.FieldSession) + return u +} + // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. // Using this option is equivalent to using: // @@ -360,6 +385,13 @@ func (u *TelegramAccountUpsertOne) UpdateCode() *TelegramAccountUpsertOne { }) } +// ClearCode clears the value of the "code" field. +func (u *TelegramAccountUpsertOne) ClearCode() *TelegramAccountUpsertOne { + return u.Update(func(s *TelegramAccountUpsert) { + s.ClearCode() + }) +} + // SetCodeAt sets the "code_at" field. func (u *TelegramAccountUpsertOne) SetCodeAt(v time.Time) *TelegramAccountUpsertOne { return u.Update(func(s *TelegramAccountUpsert) { @@ -374,6 +406,13 @@ func (u *TelegramAccountUpsertOne) UpdateCodeAt() *TelegramAccountUpsertOne { }) } +// ClearCodeAt clears the value of the "code_at" field. +func (u *TelegramAccountUpsertOne) ClearCodeAt() *TelegramAccountUpsertOne { + return u.Update(func(s *TelegramAccountUpsert) { + s.ClearCodeAt() + }) +} + // SetState sets the "state" field. func (u *TelegramAccountUpsertOne) SetState(v telegramaccount.State) *TelegramAccountUpsertOne { return u.Update(func(s *TelegramAccountUpsert) { @@ -416,6 +455,13 @@ func (u *TelegramAccountUpsertOne) UpdateSession() *TelegramAccountUpsertOne { }) } +// ClearSession clears the value of the "session" field. +func (u *TelegramAccountUpsertOne) ClearSession() *TelegramAccountUpsertOne { + return u.Update(func(s *TelegramAccountUpsert) { + s.ClearSession() + }) +} + // Exec executes the query. func (u *TelegramAccountUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { @@ -645,6 +691,13 @@ func (u *TelegramAccountUpsertBulk) UpdateCode() *TelegramAccountUpsertBulk { }) } +// ClearCode clears the value of the "code" field. +func (u *TelegramAccountUpsertBulk) ClearCode() *TelegramAccountUpsertBulk { + return u.Update(func(s *TelegramAccountUpsert) { + s.ClearCode() + }) +} + // SetCodeAt sets the "code_at" field. func (u *TelegramAccountUpsertBulk) SetCodeAt(v time.Time) *TelegramAccountUpsertBulk { return u.Update(func(s *TelegramAccountUpsert) { @@ -659,6 +712,13 @@ func (u *TelegramAccountUpsertBulk) UpdateCodeAt() *TelegramAccountUpsertBulk { }) } +// ClearCodeAt clears the value of the "code_at" field. +func (u *TelegramAccountUpsertBulk) ClearCodeAt() *TelegramAccountUpsertBulk { + return u.Update(func(s *TelegramAccountUpsert) { + s.ClearCodeAt() + }) +} + // SetState sets the "state" field. func (u *TelegramAccountUpsertBulk) SetState(v telegramaccount.State) *TelegramAccountUpsertBulk { return u.Update(func(s *TelegramAccountUpsert) { @@ -701,6 +761,13 @@ func (u *TelegramAccountUpsertBulk) UpdateSession() *TelegramAccountUpsertBulk { }) } +// ClearSession clears the value of the "session" field. +func (u *TelegramAccountUpsertBulk) ClearSession() *TelegramAccountUpsertBulk { + return u.Update(func(s *TelegramAccountUpsert) { + s.ClearSession() + }) +} + // Exec executes the query. func (u *TelegramAccountUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { diff --git a/internal/ent/telegramaccount_update.go b/internal/ent/telegramaccount_update.go index 02f8d05..bd53f8e 100644 --- a/internal/ent/telegramaccount_update.go +++ b/internal/ent/telegramaccount_update.go @@ -42,6 +42,12 @@ func (tau *TelegramAccountUpdate) SetNillableCode(s *string) *TelegramAccountUpd return tau } +// ClearCode clears the value of the "code" field. +func (tau *TelegramAccountUpdate) ClearCode() *TelegramAccountUpdate { + tau.mutation.ClearCode() + return tau +} + // SetCodeAt sets the "code_at" field. func (tau *TelegramAccountUpdate) SetCodeAt(t time.Time) *TelegramAccountUpdate { tau.mutation.SetCodeAt(t) @@ -56,6 +62,12 @@ func (tau *TelegramAccountUpdate) SetNillableCodeAt(t *time.Time) *TelegramAccou return tau } +// ClearCodeAt clears the value of the "code_at" field. +func (tau *TelegramAccountUpdate) ClearCodeAt() *TelegramAccountUpdate { + tau.mutation.ClearCodeAt() + return tau +} + // SetState sets the "state" field. func (tau *TelegramAccountUpdate) SetState(t telegramaccount.State) *TelegramAccountUpdate { tau.mutation.SetState(t) @@ -90,6 +102,12 @@ func (tau *TelegramAccountUpdate) SetSession(b []byte) *TelegramAccountUpdate { return tau } +// ClearSession clears the value of the "session" field. +func (tau *TelegramAccountUpdate) ClearSession() *TelegramAccountUpdate { + tau.mutation.ClearSession() + return tau +} + // Mutation returns the TelegramAccountMutation object of the builder. func (tau *TelegramAccountUpdate) Mutation() *TelegramAccountMutation { return tau.mutation @@ -147,9 +165,15 @@ func (tau *TelegramAccountUpdate) sqlSave(ctx context.Context) (n int, err error if value, ok := tau.mutation.Code(); ok { _spec.SetField(telegramaccount.FieldCode, field.TypeString, value) } + if tau.mutation.CodeCleared() { + _spec.ClearField(telegramaccount.FieldCode, field.TypeString) + } if value, ok := tau.mutation.CodeAt(); ok { _spec.SetField(telegramaccount.FieldCodeAt, field.TypeTime, value) } + if tau.mutation.CodeAtCleared() { + _spec.ClearField(telegramaccount.FieldCodeAt, field.TypeTime) + } if value, ok := tau.mutation.State(); ok { _spec.SetField(telegramaccount.FieldState, field.TypeEnum, value) } @@ -159,6 +183,9 @@ func (tau *TelegramAccountUpdate) sqlSave(ctx context.Context) (n int, err error if value, ok := tau.mutation.Session(); ok { _spec.SetField(telegramaccount.FieldSession, field.TypeBytes, value) } + if tau.mutation.SessionCleared() { + _spec.ClearField(telegramaccount.FieldSession, field.TypeBytes) + } if n, err = sqlgraph.UpdateNodes(ctx, tau.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{telegramaccount.Label} @@ -193,6 +220,12 @@ func (tauo *TelegramAccountUpdateOne) SetNillableCode(s *string) *TelegramAccoun return tauo } +// ClearCode clears the value of the "code" field. +func (tauo *TelegramAccountUpdateOne) ClearCode() *TelegramAccountUpdateOne { + tauo.mutation.ClearCode() + return tauo +} + // SetCodeAt sets the "code_at" field. func (tauo *TelegramAccountUpdateOne) SetCodeAt(t time.Time) *TelegramAccountUpdateOne { tauo.mutation.SetCodeAt(t) @@ -207,6 +240,12 @@ func (tauo *TelegramAccountUpdateOne) SetNillableCodeAt(t *time.Time) *TelegramA return tauo } +// ClearCodeAt clears the value of the "code_at" field. +func (tauo *TelegramAccountUpdateOne) ClearCodeAt() *TelegramAccountUpdateOne { + tauo.mutation.ClearCodeAt() + return tauo +} + // SetState sets the "state" field. func (tauo *TelegramAccountUpdateOne) SetState(t telegramaccount.State) *TelegramAccountUpdateOne { tauo.mutation.SetState(t) @@ -241,6 +280,12 @@ func (tauo *TelegramAccountUpdateOne) SetSession(b []byte) *TelegramAccountUpdat return tauo } +// ClearSession clears the value of the "session" field. +func (tauo *TelegramAccountUpdateOne) ClearSession() *TelegramAccountUpdateOne { + tauo.mutation.ClearSession() + return tauo +} + // Mutation returns the TelegramAccountMutation object of the builder. func (tauo *TelegramAccountUpdateOne) Mutation() *TelegramAccountMutation { return tauo.mutation @@ -328,9 +373,15 @@ func (tauo *TelegramAccountUpdateOne) sqlSave(ctx context.Context) (_node *Teleg if value, ok := tauo.mutation.Code(); ok { _spec.SetField(telegramaccount.FieldCode, field.TypeString, value) } + if tauo.mutation.CodeCleared() { + _spec.ClearField(telegramaccount.FieldCode, field.TypeString) + } if value, ok := tauo.mutation.CodeAt(); ok { _spec.SetField(telegramaccount.FieldCodeAt, field.TypeTime, value) } + if tauo.mutation.CodeAtCleared() { + _spec.ClearField(telegramaccount.FieldCodeAt, field.TypeTime) + } if value, ok := tauo.mutation.State(); ok { _spec.SetField(telegramaccount.FieldState, field.TypeEnum, value) } @@ -340,6 +391,9 @@ func (tauo *TelegramAccountUpdateOne) sqlSave(ctx context.Context) (_node *Teleg if value, ok := tauo.mutation.Session(); ok { _spec.SetField(telegramaccount.FieldSession, field.TypeBytes, value) } + if tauo.mutation.SessionCleared() { + _spec.ClearField(telegramaccount.FieldSession, field.TypeBytes) + } _node = &TelegramAccount{config: tauo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/internal/tgmanager/account.go b/internal/tgmanager/account.go index cb02d7b..3101d8e 100644 --- a/internal/tgmanager/account.go +++ b/internal/tgmanager/account.go @@ -132,7 +132,7 @@ func (a *Account) WaitForCode(ctx context.Context, code *tg.AuthSentCode) (ret s if err != nil { return "", errors.Wrap(err, "get account") } - if acc.Code == "" { + if acc.Code == nil || acc.CodeAt == nil || *acc.Code == "" { a.lg.Info("Code not received") continue } @@ -140,7 +140,7 @@ func (a *Account) WaitForCode(ctx context.Context, code *tg.AuthSentCode) (ret s a.lg.Info("Code expired") continue } - return acc.Code, nil + return *acc.Code, nil } } } diff --git a/migrations/20241208112922_telegram_acc_nillable.sql b/migrations/20241208112922_telegram_acc_nillable.sql new file mode 100644 index 0000000..db671cb --- /dev/null +++ b/migrations/20241208112922_telegram_acc_nillable.sql @@ -0,0 +1,2 @@ +-- Modify "telegram_accounts" table +ALTER TABLE "telegram_accounts" ALTER COLUMN "code" DROP NOT NULL, ALTER COLUMN "code_at" DROP NOT NULL, ALTER COLUMN "session" DROP NOT NULL; diff --git a/migrations/atlas.sum b/migrations/atlas.sum index 4b39434..47ee140 100644 --- a/migrations/atlas.sum +++ b/migrations/atlas.sum @@ -1,5 +1,6 @@ -h1:jVw8mJ9DWJlb82KnZ9XNQD2RFRWrm4g6r1HSeuk85NM= +h1:5C0IdkpaN76MM4FA+q3LW5JJ2RBRaZeFAejMSa0++Yg= 20241202075819_init.sql h1:r0lJLQNwt57c2NIRwSmfUM+3yL/2NOZ4seeGxvzgVj0= 20241208073032_telegram_account.sql h1:ImERWJTnJnTlfPeZjktBmu+f/jDCVRcnZ9Mhep9W52Y= 20241208082152_telegram_acc_session.sql h1:7zf4FeSz/FDlB0tknYtu1y4PCDa5G55Q5HckDmwJwVA= 20241208112252_telegram_acc_nillable.sql h1:bpSNEnZ+iExgRcSmNqBJyFvUtPn9pShWmHSPehlrGfo= +20241208112922_telegram_acc_nillable.sql h1:iBcHFUbhPdLiEhvJxekB/Z+ijdvj8hdedpR3EI9U3JA=