diff --git a/backend/ent/channelmonitordailyrollup.go b/backend/ent/channelmonitordailyrollup.go index 6c7a8afa..78a5f489 100644 --- a/backend/ent/channelmonitordailyrollup.go +++ b/backend/ent/channelmonitordailyrollup.go @@ -18,8 +18,6 @@ type ChannelMonitorDailyRollup struct { config `json:"-"` // ID of the ent. ID int64 `json:"id,omitempty"` - // DeletedAt holds the value of the "deleted_at" field. - DeletedAt *time.Time `json:"deleted_at,omitempty"` // MonitorID holds the value of the "monitor_id" field. MonitorID int64 `json:"monitor_id,omitempty"` // Model holds the value of the "model" field. @@ -83,7 +81,7 @@ func (*ChannelMonitorDailyRollup) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullInt64) case channelmonitordailyrollup.FieldModel: values[i] = new(sql.NullString) - case channelmonitordailyrollup.FieldDeletedAt, channelmonitordailyrollup.FieldBucketDate, channelmonitordailyrollup.FieldComputedAt: + case channelmonitordailyrollup.FieldBucketDate, channelmonitordailyrollup.FieldComputedAt: values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) @@ -106,13 +104,6 @@ func (_m *ChannelMonitorDailyRollup) assignValues(columns []string, values []any return fmt.Errorf("unexpected type %T for field id", value) } _m.ID = int64(value.Int64) - case channelmonitordailyrollup.FieldDeletedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field deleted_at", values[i]) - } else if value.Valid { - _m.DeletedAt = new(time.Time) - *_m.DeletedAt = value.Time - } case channelmonitordailyrollup.FieldMonitorID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field monitor_id", values[i]) @@ -238,11 +229,6 @@ func (_m *ChannelMonitorDailyRollup) String() string { var builder strings.Builder builder.WriteString("ChannelMonitorDailyRollup(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - if v := _m.DeletedAt; v != nil { - builder.WriteString("deleted_at=") - builder.WriteString(v.Format(time.ANSIC)) - } - builder.WriteString(", ") builder.WriteString("monitor_id=") builder.WriteString(fmt.Sprintf("%v", _m.MonitorID)) builder.WriteString(", ") diff --git a/backend/ent/channelmonitordailyrollup/channelmonitordailyrollup.go b/backend/ent/channelmonitordailyrollup/channelmonitordailyrollup.go index eb1f69a8..e7cb9307 100644 --- a/backend/ent/channelmonitordailyrollup/channelmonitordailyrollup.go +++ b/backend/ent/channelmonitordailyrollup/channelmonitordailyrollup.go @@ -5,7 +5,6 @@ package channelmonitordailyrollup import ( "time" - "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" ) @@ -15,8 +14,6 @@ const ( Label = "channel_monitor_daily_rollup" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldDeletedAt holds the string denoting the deleted_at field in the database. - FieldDeletedAt = "deleted_at" // FieldMonitorID holds the string denoting the monitor_id field in the database. FieldMonitorID = "monitor_id" // FieldModel holds the string denoting the model field in the database. @@ -61,7 +58,6 @@ const ( // Columns holds all SQL columns for channelmonitordailyrollup fields. var Columns = []string{ FieldID, - FieldDeletedAt, FieldMonitorID, FieldModel, FieldBucketDate, @@ -88,14 +84,7 @@ func ValidColumn(column string) bool { return false } -// Note that the variables below are initialized by the runtime -// package on the initialization of the application. Therefore, -// it should be imported in the main as follows: -// -// import _ "github.com/Wei-Shaw/sub2api/ent/runtime" var ( - Hooks [1]ent.Hook - Interceptors [1]ent.Interceptor // ModelValidator is a validator for the "model" field. It is called by the builders before save. ModelValidator func(string) error // DefaultTotalChecks holds the default value on creation for the "total_checks" field. @@ -132,11 +121,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByDeletedAt orders the results by the deleted_at field. -func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() -} - // ByMonitorID orders the results by the monitor_id field. func ByMonitorID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldMonitorID, opts...).ToFunc() diff --git a/backend/ent/channelmonitordailyrollup/where.go b/backend/ent/channelmonitordailyrollup/where.go index 9da8d4be..424c957e 100644 --- a/backend/ent/channelmonitordailyrollup/where.go +++ b/backend/ent/channelmonitordailyrollup/where.go @@ -55,11 +55,6 @@ func IDLTE(id int64) predicate.ChannelMonitorDailyRollup { return predicate.ChannelMonitorDailyRollup(sql.FieldLTE(FieldID, id)) } -// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ. -func DeletedAt(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldEQ(FieldDeletedAt, v)) -} - // MonitorID applies equality check predicate on the "monitor_id" field. It's identical to MonitorIDEQ. func MonitorID(v int64) predicate.ChannelMonitorDailyRollup { return predicate.ChannelMonitorDailyRollup(sql.FieldEQ(FieldMonitorID, v)) @@ -130,56 +125,6 @@ func ComputedAt(v time.Time) predicate.ChannelMonitorDailyRollup { return predicate.ChannelMonitorDailyRollup(sql.FieldEQ(FieldComputedAt, v)) } -// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. -func DeletedAtEQ(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldEQ(FieldDeletedAt, v)) -} - -// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. -func DeletedAtNEQ(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldNEQ(FieldDeletedAt, v)) -} - -// DeletedAtIn applies the In predicate on the "deleted_at" field. -func DeletedAtIn(vs ...time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldIn(FieldDeletedAt, vs...)) -} - -// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. -func DeletedAtNotIn(vs ...time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldNotIn(FieldDeletedAt, vs...)) -} - -// DeletedAtGT applies the GT predicate on the "deleted_at" field. -func DeletedAtGT(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldGT(FieldDeletedAt, v)) -} - -// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. -func DeletedAtGTE(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldGTE(FieldDeletedAt, v)) -} - -// DeletedAtLT applies the LT predicate on the "deleted_at" field. -func DeletedAtLT(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldLT(FieldDeletedAt, v)) -} - -// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. -func DeletedAtLTE(v time.Time) predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldLTE(FieldDeletedAt, v)) -} - -// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. -func DeletedAtIsNil() predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldIsNull(FieldDeletedAt)) -} - -// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. -func DeletedAtNotNil() predicate.ChannelMonitorDailyRollup { - return predicate.ChannelMonitorDailyRollup(sql.FieldNotNull(FieldDeletedAt)) -} - // MonitorIDEQ applies the EQ predicate on the "monitor_id" field. func MonitorIDEQ(v int64) predicate.ChannelMonitorDailyRollup { return predicate.ChannelMonitorDailyRollup(sql.FieldEQ(FieldMonitorID, v)) diff --git a/backend/ent/channelmonitordailyrollup_create.go b/backend/ent/channelmonitordailyrollup_create.go index c4850751..5f8754ba 100644 --- a/backend/ent/channelmonitordailyrollup_create.go +++ b/backend/ent/channelmonitordailyrollup_create.go @@ -23,20 +23,6 @@ type ChannelMonitorDailyRollupCreate struct { conflict []sql.ConflictOption } -// SetDeletedAt sets the "deleted_at" field. -func (_c *ChannelMonitorDailyRollupCreate) SetDeletedAt(v time.Time) *ChannelMonitorDailyRollupCreate { - _c.mutation.SetDeletedAt(v) - return _c -} - -// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. -func (_c *ChannelMonitorDailyRollupCreate) SetNillableDeletedAt(v *time.Time) *ChannelMonitorDailyRollupCreate { - if v != nil { - _c.SetDeletedAt(*v) - } - return _c -} - // SetMonitorID sets the "monitor_id" field. func (_c *ChannelMonitorDailyRollupCreate) SetMonitorID(v int64) *ChannelMonitorDailyRollupCreate { _c.mutation.SetMonitorID(v) @@ -221,9 +207,7 @@ func (_c *ChannelMonitorDailyRollupCreate) Mutation() *ChannelMonitorDailyRollup // Save creates the ChannelMonitorDailyRollup in the database. func (_c *ChannelMonitorDailyRollupCreate) Save(ctx context.Context) (*ChannelMonitorDailyRollup, error) { - if err := _c.defaults(); err != nil { - return nil, err - } + _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } @@ -250,7 +234,7 @@ func (_c *ChannelMonitorDailyRollupCreate) ExecX(ctx context.Context) { } // defaults sets the default values of the builder before save. -func (_c *ChannelMonitorDailyRollupCreate) defaults() error { +func (_c *ChannelMonitorDailyRollupCreate) defaults() { if _, ok := _c.mutation.TotalChecks(); !ok { v := channelmonitordailyrollup.DefaultTotalChecks _c.mutation.SetTotalChecks(v) @@ -292,13 +276,9 @@ func (_c *ChannelMonitorDailyRollupCreate) defaults() error { _c.mutation.SetCountPingLatency(v) } if _, ok := _c.mutation.ComputedAt(); !ok { - if channelmonitordailyrollup.DefaultComputedAt == nil { - return fmt.Errorf("ent: uninitialized channelmonitordailyrollup.DefaultComputedAt (forgotten import ent/runtime?)") - } v := channelmonitordailyrollup.DefaultComputedAt() _c.mutation.SetComputedAt(v) } - return nil } // check runs all checks and user-defined validators on the builder. @@ -380,10 +360,6 @@ func (_c *ChannelMonitorDailyRollupCreate) createSpec() (*ChannelMonitorDailyRol _spec = sqlgraph.NewCreateSpec(channelmonitordailyrollup.Table, sqlgraph.NewFieldSpec(channelmonitordailyrollup.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict - if value, ok := _c.mutation.DeletedAt(); ok { - _spec.SetField(channelmonitordailyrollup.FieldDeletedAt, field.TypeTime, value) - _node.DeletedAt = &value - } if value, ok := _c.mutation.Model(); ok { _spec.SetField(channelmonitordailyrollup.FieldModel, field.TypeString, value) _node.Model = value @@ -460,7 +436,7 @@ func (_c *ChannelMonitorDailyRollupCreate) createSpec() (*ChannelMonitorDailyRol // of the `INSERT` statement. For example: // // client.ChannelMonitorDailyRollup.Create(). -// SetDeletedAt(v). +// SetMonitorID(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -469,7 +445,7 @@ func (_c *ChannelMonitorDailyRollupCreate) createSpec() (*ChannelMonitorDailyRol // // Override some of the fields with custom // // update values. // Update(func(u *ent.ChannelMonitorDailyRollupUpsert) { -// SetDeletedAt(v+v). +// SetMonitorID(v+v). // }). // Exec(ctx) func (_c *ChannelMonitorDailyRollupCreate) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorDailyRollupUpsertOne { @@ -505,24 +481,6 @@ type ( } ) -// SetDeletedAt sets the "deleted_at" field. -func (u *ChannelMonitorDailyRollupUpsert) SetDeletedAt(v time.Time) *ChannelMonitorDailyRollupUpsert { - u.Set(channelmonitordailyrollup.FieldDeletedAt, v) - return u -} - -// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. -func (u *ChannelMonitorDailyRollupUpsert) UpdateDeletedAt() *ChannelMonitorDailyRollupUpsert { - u.SetExcluded(channelmonitordailyrollup.FieldDeletedAt) - return u -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (u *ChannelMonitorDailyRollupUpsert) ClearDeletedAt() *ChannelMonitorDailyRollupUpsert { - u.SetNull(channelmonitordailyrollup.FieldDeletedAt) - return u -} - // SetMonitorID sets the "monitor_id" field. func (u *ChannelMonitorDailyRollupUpsert) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpsert { u.Set(channelmonitordailyrollup.FieldMonitorID, v) @@ -791,27 +749,6 @@ func (u *ChannelMonitorDailyRollupUpsertOne) Update(set func(*ChannelMonitorDail return u } -// SetDeletedAt sets the "deleted_at" field. -func (u *ChannelMonitorDailyRollupUpsertOne) SetDeletedAt(v time.Time) *ChannelMonitorDailyRollupUpsertOne { - return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { - s.SetDeletedAt(v) - }) -} - -// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. -func (u *ChannelMonitorDailyRollupUpsertOne) UpdateDeletedAt() *ChannelMonitorDailyRollupUpsertOne { - return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { - s.UpdateDeletedAt() - }) -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (u *ChannelMonitorDailyRollupUpsertOne) ClearDeletedAt() *ChannelMonitorDailyRollupUpsertOne { - return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { - s.ClearDeletedAt() - }) -} - // SetMonitorID sets the "monitor_id" field. func (u *ChannelMonitorDailyRollupUpsertOne) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpsertOne { return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { @@ -1213,7 +1150,7 @@ func (_c *ChannelMonitorDailyRollupCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.ChannelMonitorDailyRollupUpsert) { -// SetDeletedAt(v+v). +// SetMonitorID(v+v). // }). // Exec(ctx) func (_c *ChannelMonitorDailyRollupCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorDailyRollupUpsertBulk { @@ -1282,27 +1219,6 @@ func (u *ChannelMonitorDailyRollupUpsertBulk) Update(set func(*ChannelMonitorDai return u } -// SetDeletedAt sets the "deleted_at" field. -func (u *ChannelMonitorDailyRollupUpsertBulk) SetDeletedAt(v time.Time) *ChannelMonitorDailyRollupUpsertBulk { - return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { - s.SetDeletedAt(v) - }) -} - -// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. -func (u *ChannelMonitorDailyRollupUpsertBulk) UpdateDeletedAt() *ChannelMonitorDailyRollupUpsertBulk { - return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { - s.UpdateDeletedAt() - }) -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (u *ChannelMonitorDailyRollupUpsertBulk) ClearDeletedAt() *ChannelMonitorDailyRollupUpsertBulk { - return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { - s.ClearDeletedAt() - }) -} - // SetMonitorID sets the "monitor_id" field. func (u *ChannelMonitorDailyRollupUpsertBulk) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpsertBulk { return u.Update(func(s *ChannelMonitorDailyRollupUpsert) { diff --git a/backend/ent/channelmonitordailyrollup_query.go b/backend/ent/channelmonitordailyrollup_query.go index 30528575..e34afc61 100644 --- a/backend/ent/channelmonitordailyrollup_query.go +++ b/backend/ent/channelmonitordailyrollup_query.go @@ -300,12 +300,12 @@ func (_q *ChannelMonitorDailyRollupQuery) WithMonitor(opts ...func(*ChannelMonit // Example: // // var v []struct { -// DeletedAt time.Time `json:"deleted_at,omitempty"` +// MonitorID int64 `json:"monitor_id,omitempty"` // Count int `json:"count,omitempty"` // } // // client.ChannelMonitorDailyRollup.Query(). -// GroupBy(channelmonitordailyrollup.FieldDeletedAt). +// GroupBy(channelmonitordailyrollup.FieldMonitorID). // Aggregate(ent.Count()). // Scan(ctx, &v) func (_q *ChannelMonitorDailyRollupQuery) GroupBy(field string, fields ...string) *ChannelMonitorDailyRollupGroupBy { @@ -323,11 +323,11 @@ func (_q *ChannelMonitorDailyRollupQuery) GroupBy(field string, fields ...string // Example: // // var v []struct { -// DeletedAt time.Time `json:"deleted_at,omitempty"` +// MonitorID int64 `json:"monitor_id,omitempty"` // } // // client.ChannelMonitorDailyRollup.Query(). -// Select(channelmonitordailyrollup.FieldDeletedAt). +// Select(channelmonitordailyrollup.FieldMonitorID). // Scan(ctx, &v) func (_q *ChannelMonitorDailyRollupQuery) Select(fields ...string) *ChannelMonitorDailyRollupSelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) diff --git a/backend/ent/channelmonitordailyrollup_update.go b/backend/ent/channelmonitordailyrollup_update.go index 0b82f8bf..02cd86c5 100644 --- a/backend/ent/channelmonitordailyrollup_update.go +++ b/backend/ent/channelmonitordailyrollup_update.go @@ -29,26 +29,6 @@ func (_u *ChannelMonitorDailyRollupUpdate) Where(ps ...predicate.ChannelMonitorD return _u } -// SetDeletedAt sets the "deleted_at" field. -func (_u *ChannelMonitorDailyRollupUpdate) SetDeletedAt(v time.Time) *ChannelMonitorDailyRollupUpdate { - _u.mutation.SetDeletedAt(v) - return _u -} - -// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. -func (_u *ChannelMonitorDailyRollupUpdate) SetNillableDeletedAt(v *time.Time) *ChannelMonitorDailyRollupUpdate { - if v != nil { - _u.SetDeletedAt(*v) - } - return _u -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (_u *ChannelMonitorDailyRollupUpdate) ClearDeletedAt() *ChannelMonitorDailyRollupUpdate { - _u.mutation.ClearDeletedAt() - return _u -} - // SetMonitorID sets the "monitor_id" field. func (_u *ChannelMonitorDailyRollupUpdate) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpdate { _u.mutation.SetMonitorID(v) @@ -325,9 +305,7 @@ func (_u *ChannelMonitorDailyRollupUpdate) ClearMonitor() *ChannelMonitorDailyRo // Save executes the query and returns the number of nodes affected by the update operation. func (_u *ChannelMonitorDailyRollupUpdate) Save(ctx context.Context) (int, error) { - if err := _u.defaults(); err != nil { - return 0, err - } + _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } @@ -354,15 +332,11 @@ func (_u *ChannelMonitorDailyRollupUpdate) ExecX(ctx context.Context) { } // defaults sets the default values of the builder before save. -func (_u *ChannelMonitorDailyRollupUpdate) defaults() error { +func (_u *ChannelMonitorDailyRollupUpdate) defaults() { if _, ok := _u.mutation.ComputedAt(); !ok { - if channelmonitordailyrollup.UpdateDefaultComputedAt == nil { - return fmt.Errorf("ent: uninitialized channelmonitordailyrollup.UpdateDefaultComputedAt (forgotten import ent/runtime?)") - } v := channelmonitordailyrollup.UpdateDefaultComputedAt() _u.mutation.SetComputedAt(v) } - return nil } // check runs all checks and user-defined validators on the builder. @@ -390,12 +364,6 @@ func (_u *ChannelMonitorDailyRollupUpdate) sqlSave(ctx context.Context) (_node i } } } - if value, ok := _u.mutation.DeletedAt(); ok { - _spec.SetField(channelmonitordailyrollup.FieldDeletedAt, field.TypeTime, value) - } - if _u.mutation.DeletedAtCleared() { - _spec.ClearField(channelmonitordailyrollup.FieldDeletedAt, field.TypeTime) - } if value, ok := _u.mutation.Model(); ok { _spec.SetField(channelmonitordailyrollup.FieldModel, field.TypeString, value) } @@ -514,26 +482,6 @@ type ChannelMonitorDailyRollupUpdateOne struct { mutation *ChannelMonitorDailyRollupMutation } -// SetDeletedAt sets the "deleted_at" field. -func (_u *ChannelMonitorDailyRollupUpdateOne) SetDeletedAt(v time.Time) *ChannelMonitorDailyRollupUpdateOne { - _u.mutation.SetDeletedAt(v) - return _u -} - -// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. -func (_u *ChannelMonitorDailyRollupUpdateOne) SetNillableDeletedAt(v *time.Time) *ChannelMonitorDailyRollupUpdateOne { - if v != nil { - _u.SetDeletedAt(*v) - } - return _u -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (_u *ChannelMonitorDailyRollupUpdateOne) ClearDeletedAt() *ChannelMonitorDailyRollupUpdateOne { - _u.mutation.ClearDeletedAt() - return _u -} - // SetMonitorID sets the "monitor_id" field. func (_u *ChannelMonitorDailyRollupUpdateOne) SetMonitorID(v int64) *ChannelMonitorDailyRollupUpdateOne { _u.mutation.SetMonitorID(v) @@ -823,9 +771,7 @@ func (_u *ChannelMonitorDailyRollupUpdateOne) Select(field string, fields ...str // Save executes the query and returns the updated ChannelMonitorDailyRollup entity. func (_u *ChannelMonitorDailyRollupUpdateOne) Save(ctx context.Context) (*ChannelMonitorDailyRollup, error) { - if err := _u.defaults(); err != nil { - return nil, err - } + _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } @@ -852,15 +798,11 @@ func (_u *ChannelMonitorDailyRollupUpdateOne) ExecX(ctx context.Context) { } // defaults sets the default values of the builder before save. -func (_u *ChannelMonitorDailyRollupUpdateOne) defaults() error { +func (_u *ChannelMonitorDailyRollupUpdateOne) defaults() { if _, ok := _u.mutation.ComputedAt(); !ok { - if channelmonitordailyrollup.UpdateDefaultComputedAt == nil { - return fmt.Errorf("ent: uninitialized channelmonitordailyrollup.UpdateDefaultComputedAt (forgotten import ent/runtime?)") - } v := channelmonitordailyrollup.UpdateDefaultComputedAt() _u.mutation.SetComputedAt(v) } - return nil } // check runs all checks and user-defined validators on the builder. @@ -905,12 +847,6 @@ func (_u *ChannelMonitorDailyRollupUpdateOne) sqlSave(ctx context.Context) (_nod } } } - if value, ok := _u.mutation.DeletedAt(); ok { - _spec.SetField(channelmonitordailyrollup.FieldDeletedAt, field.TypeTime, value) - } - if _u.mutation.DeletedAtCleared() { - _spec.ClearField(channelmonitordailyrollup.FieldDeletedAt, field.TypeTime) - } if value, ok := _u.mutation.Model(); ok { _spec.SetField(channelmonitordailyrollup.FieldModel, field.TypeString, value) } diff --git a/backend/ent/channelmonitorhistory.go b/backend/ent/channelmonitorhistory.go index 256eaf5f..70dde542 100644 --- a/backend/ent/channelmonitorhistory.go +++ b/backend/ent/channelmonitorhistory.go @@ -18,8 +18,6 @@ type ChannelMonitorHistory struct { config `json:"-"` // ID of the ent. ID int64 `json:"id,omitempty"` - // DeletedAt holds the value of the "deleted_at" field. - DeletedAt *time.Time `json:"deleted_at,omitempty"` // MonitorID holds the value of the "monitor_id" field. MonitorID int64 `json:"monitor_id,omitempty"` // Model holds the value of the "model" field. @@ -69,7 +67,7 @@ func (*ChannelMonitorHistory) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullInt64) case channelmonitorhistory.FieldModel, channelmonitorhistory.FieldStatus, channelmonitorhistory.FieldMessage: values[i] = new(sql.NullString) - case channelmonitorhistory.FieldDeletedAt, channelmonitorhistory.FieldCheckedAt: + case channelmonitorhistory.FieldCheckedAt: values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) @@ -92,13 +90,6 @@ func (_m *ChannelMonitorHistory) assignValues(columns []string, values []any) er return fmt.Errorf("unexpected type %T for field id", value) } _m.ID = int64(value.Int64) - case channelmonitorhistory.FieldDeletedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field deleted_at", values[i]) - } else if value.Valid { - _m.DeletedAt = new(time.Time) - *_m.DeletedAt = value.Time - } case channelmonitorhistory.FieldMonitorID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field monitor_id", values[i]) @@ -184,11 +175,6 @@ func (_m *ChannelMonitorHistory) String() string { var builder strings.Builder builder.WriteString("ChannelMonitorHistory(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - if v := _m.DeletedAt; v != nil { - builder.WriteString("deleted_at=") - builder.WriteString(v.Format(time.ANSIC)) - } - builder.WriteString(", ") builder.WriteString("monitor_id=") builder.WriteString(fmt.Sprintf("%v", _m.MonitorID)) builder.WriteString(", ") diff --git a/backend/ent/channelmonitorhistory/channelmonitorhistory.go b/backend/ent/channelmonitorhistory/channelmonitorhistory.go index da59791b..6a9dc006 100644 --- a/backend/ent/channelmonitorhistory/channelmonitorhistory.go +++ b/backend/ent/channelmonitorhistory/channelmonitorhistory.go @@ -6,7 +6,6 @@ import ( "fmt" "time" - "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" ) @@ -16,8 +15,6 @@ const ( Label = "channel_monitor_history" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldDeletedAt holds the string denoting the deleted_at field in the database. - FieldDeletedAt = "deleted_at" // FieldMonitorID holds the string denoting the monitor_id field in the database. FieldMonitorID = "monitor_id" // FieldModel holds the string denoting the model field in the database. @@ -48,7 +45,6 @@ const ( // Columns holds all SQL columns for channelmonitorhistory fields. var Columns = []string{ FieldID, - FieldDeletedAt, FieldMonitorID, FieldModel, FieldStatus, @@ -68,14 +64,7 @@ func ValidColumn(column string) bool { return false } -// Note that the variables below are initialized by the runtime -// package on the initialization of the application. Therefore, -// it should be imported in the main as follows: -// -// import _ "github.com/Wei-Shaw/sub2api/ent/runtime" var ( - Hooks [1]ent.Hook - Interceptors [1]ent.Interceptor // ModelValidator is a validator for the "model" field. It is called by the builders before save. ModelValidator func(string) error // DefaultMessage holds the default value on creation for the "message" field. @@ -119,11 +108,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByDeletedAt orders the results by the deleted_at field. -func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() -} - // ByMonitorID orders the results by the monitor_id field. func ByMonitorID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldMonitorID, opts...).ToFunc() diff --git a/backend/ent/channelmonitorhistory/where.go b/backend/ent/channelmonitorhistory/where.go index 7b1cd50d..afa73f35 100644 --- a/backend/ent/channelmonitorhistory/where.go +++ b/backend/ent/channelmonitorhistory/where.go @@ -55,11 +55,6 @@ func IDLTE(id int64) predicate.ChannelMonitorHistory { return predicate.ChannelMonitorHistory(sql.FieldLTE(FieldID, id)) } -// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ. -func DeletedAt(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldEQ(FieldDeletedAt, v)) -} - // MonitorID applies equality check predicate on the "monitor_id" field. It's identical to MonitorIDEQ. func MonitorID(v int64) predicate.ChannelMonitorHistory { return predicate.ChannelMonitorHistory(sql.FieldEQ(FieldMonitorID, v)) @@ -90,56 +85,6 @@ func CheckedAt(v time.Time) predicate.ChannelMonitorHistory { return predicate.ChannelMonitorHistory(sql.FieldEQ(FieldCheckedAt, v)) } -// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. -func DeletedAtEQ(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldEQ(FieldDeletedAt, v)) -} - -// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. -func DeletedAtNEQ(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldNEQ(FieldDeletedAt, v)) -} - -// DeletedAtIn applies the In predicate on the "deleted_at" field. -func DeletedAtIn(vs ...time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldIn(FieldDeletedAt, vs...)) -} - -// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. -func DeletedAtNotIn(vs ...time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldNotIn(FieldDeletedAt, vs...)) -} - -// DeletedAtGT applies the GT predicate on the "deleted_at" field. -func DeletedAtGT(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldGT(FieldDeletedAt, v)) -} - -// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. -func DeletedAtGTE(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldGTE(FieldDeletedAt, v)) -} - -// DeletedAtLT applies the LT predicate on the "deleted_at" field. -func DeletedAtLT(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldLT(FieldDeletedAt, v)) -} - -// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. -func DeletedAtLTE(v time.Time) predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldLTE(FieldDeletedAt, v)) -} - -// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. -func DeletedAtIsNil() predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldIsNull(FieldDeletedAt)) -} - -// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. -func DeletedAtNotNil() predicate.ChannelMonitorHistory { - return predicate.ChannelMonitorHistory(sql.FieldNotNull(FieldDeletedAt)) -} - // MonitorIDEQ applies the EQ predicate on the "monitor_id" field. func MonitorIDEQ(v int64) predicate.ChannelMonitorHistory { return predicate.ChannelMonitorHistory(sql.FieldEQ(FieldMonitorID, v)) diff --git a/backend/ent/channelmonitorhistory_create.go b/backend/ent/channelmonitorhistory_create.go index 9a68c9ce..71034865 100644 --- a/backend/ent/channelmonitorhistory_create.go +++ b/backend/ent/channelmonitorhistory_create.go @@ -23,20 +23,6 @@ type ChannelMonitorHistoryCreate struct { conflict []sql.ConflictOption } -// SetDeletedAt sets the "deleted_at" field. -func (_c *ChannelMonitorHistoryCreate) SetDeletedAt(v time.Time) *ChannelMonitorHistoryCreate { - _c.mutation.SetDeletedAt(v) - return _c -} - -// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. -func (_c *ChannelMonitorHistoryCreate) SetNillableDeletedAt(v *time.Time) *ChannelMonitorHistoryCreate { - if v != nil { - _c.SetDeletedAt(*v) - } - return _c -} - // SetMonitorID sets the "monitor_id" field. func (_c *ChannelMonitorHistoryCreate) SetMonitorID(v int64) *ChannelMonitorHistoryCreate { _c.mutation.SetMonitorID(v) @@ -123,9 +109,7 @@ func (_c *ChannelMonitorHistoryCreate) Mutation() *ChannelMonitorHistoryMutation // Save creates the ChannelMonitorHistory in the database. func (_c *ChannelMonitorHistoryCreate) Save(ctx context.Context) (*ChannelMonitorHistory, error) { - if err := _c.defaults(); err != nil { - return nil, err - } + _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } @@ -152,19 +136,15 @@ func (_c *ChannelMonitorHistoryCreate) ExecX(ctx context.Context) { } // defaults sets the default values of the builder before save. -func (_c *ChannelMonitorHistoryCreate) defaults() error { +func (_c *ChannelMonitorHistoryCreate) defaults() { if _, ok := _c.mutation.Message(); !ok { v := channelmonitorhistory.DefaultMessage _c.mutation.SetMessage(v) } if _, ok := _c.mutation.CheckedAt(); !ok { - if channelmonitorhistory.DefaultCheckedAt == nil { - return fmt.Errorf("ent: uninitialized channelmonitorhistory.DefaultCheckedAt (forgotten import ent/runtime?)") - } v := channelmonitorhistory.DefaultCheckedAt() _c.mutation.SetCheckedAt(v) } - return nil } // check runs all checks and user-defined validators on the builder. @@ -226,10 +206,6 @@ func (_c *ChannelMonitorHistoryCreate) createSpec() (*ChannelMonitorHistory, *sq _spec = sqlgraph.NewCreateSpec(channelmonitorhistory.Table, sqlgraph.NewFieldSpec(channelmonitorhistory.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict - if value, ok := _c.mutation.DeletedAt(); ok { - _spec.SetField(channelmonitorhistory.FieldDeletedAt, field.TypeTime, value) - _node.DeletedAt = &value - } if value, ok := _c.mutation.Model(); ok { _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value) _node.Model = value @@ -278,7 +254,7 @@ func (_c *ChannelMonitorHistoryCreate) createSpec() (*ChannelMonitorHistory, *sq // of the `INSERT` statement. For example: // // client.ChannelMonitorHistory.Create(). -// SetDeletedAt(v). +// SetMonitorID(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -287,7 +263,7 @@ func (_c *ChannelMonitorHistoryCreate) createSpec() (*ChannelMonitorHistory, *sq // // Override some of the fields with custom // // update values. // Update(func(u *ent.ChannelMonitorHistoryUpsert) { -// SetDeletedAt(v+v). +// SetMonitorID(v+v). // }). // Exec(ctx) func (_c *ChannelMonitorHistoryCreate) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorHistoryUpsertOne { @@ -323,24 +299,6 @@ type ( } ) -// SetDeletedAt sets the "deleted_at" field. -func (u *ChannelMonitorHistoryUpsert) SetDeletedAt(v time.Time) *ChannelMonitorHistoryUpsert { - u.Set(channelmonitorhistory.FieldDeletedAt, v) - return u -} - -// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. -func (u *ChannelMonitorHistoryUpsert) UpdateDeletedAt() *ChannelMonitorHistoryUpsert { - u.SetExcluded(channelmonitorhistory.FieldDeletedAt) - return u -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (u *ChannelMonitorHistoryUpsert) ClearDeletedAt() *ChannelMonitorHistoryUpsert { - u.SetNull(channelmonitorhistory.FieldDeletedAt) - return u -} - // SetMonitorID sets the "monitor_id" field. func (u *ChannelMonitorHistoryUpsert) SetMonitorID(v int64) *ChannelMonitorHistoryUpsert { u.Set(channelmonitorhistory.FieldMonitorID, v) @@ -495,27 +453,6 @@ func (u *ChannelMonitorHistoryUpsertOne) Update(set func(*ChannelMonitorHistoryU return u } -// SetDeletedAt sets the "deleted_at" field. -func (u *ChannelMonitorHistoryUpsertOne) SetDeletedAt(v time.Time) *ChannelMonitorHistoryUpsertOne { - return u.Update(func(s *ChannelMonitorHistoryUpsert) { - s.SetDeletedAt(v) - }) -} - -// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. -func (u *ChannelMonitorHistoryUpsertOne) UpdateDeletedAt() *ChannelMonitorHistoryUpsertOne { - return u.Update(func(s *ChannelMonitorHistoryUpsert) { - s.UpdateDeletedAt() - }) -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (u *ChannelMonitorHistoryUpsertOne) ClearDeletedAt() *ChannelMonitorHistoryUpsertOne { - return u.Update(func(s *ChannelMonitorHistoryUpsert) { - s.ClearDeletedAt() - }) -} - // SetMonitorID sets the "monitor_id" field. func (u *ChannelMonitorHistoryUpsertOne) SetMonitorID(v int64) *ChannelMonitorHistoryUpsertOne { return u.Update(func(s *ChannelMonitorHistoryUpsert) { @@ -784,7 +721,7 @@ func (_c *ChannelMonitorHistoryCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.ChannelMonitorHistoryUpsert) { -// SetDeletedAt(v+v). +// SetMonitorID(v+v). // }). // Exec(ctx) func (_c *ChannelMonitorHistoryCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChannelMonitorHistoryUpsertBulk { @@ -853,27 +790,6 @@ func (u *ChannelMonitorHistoryUpsertBulk) Update(set func(*ChannelMonitorHistory return u } -// SetDeletedAt sets the "deleted_at" field. -func (u *ChannelMonitorHistoryUpsertBulk) SetDeletedAt(v time.Time) *ChannelMonitorHistoryUpsertBulk { - return u.Update(func(s *ChannelMonitorHistoryUpsert) { - s.SetDeletedAt(v) - }) -} - -// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. -func (u *ChannelMonitorHistoryUpsertBulk) UpdateDeletedAt() *ChannelMonitorHistoryUpsertBulk { - return u.Update(func(s *ChannelMonitorHistoryUpsert) { - s.UpdateDeletedAt() - }) -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (u *ChannelMonitorHistoryUpsertBulk) ClearDeletedAt() *ChannelMonitorHistoryUpsertBulk { - return u.Update(func(s *ChannelMonitorHistoryUpsert) { - s.ClearDeletedAt() - }) -} - // SetMonitorID sets the "monitor_id" field. func (u *ChannelMonitorHistoryUpsertBulk) SetMonitorID(v int64) *ChannelMonitorHistoryUpsertBulk { return u.Update(func(s *ChannelMonitorHistoryUpsert) { diff --git a/backend/ent/channelmonitorhistory_query.go b/backend/ent/channelmonitorhistory_query.go index 26a1528f..1fb872ad 100644 --- a/backend/ent/channelmonitorhistory_query.go +++ b/backend/ent/channelmonitorhistory_query.go @@ -300,12 +300,12 @@ func (_q *ChannelMonitorHistoryQuery) WithMonitor(opts ...func(*ChannelMonitorQu // Example: // // var v []struct { -// DeletedAt time.Time `json:"deleted_at,omitempty"` +// MonitorID int64 `json:"monitor_id,omitempty"` // Count int `json:"count,omitempty"` // } // // client.ChannelMonitorHistory.Query(). -// GroupBy(channelmonitorhistory.FieldDeletedAt). +// GroupBy(channelmonitorhistory.FieldMonitorID). // Aggregate(ent.Count()). // Scan(ctx, &v) func (_q *ChannelMonitorHistoryQuery) GroupBy(field string, fields ...string) *ChannelMonitorHistoryGroupBy { @@ -323,11 +323,11 @@ func (_q *ChannelMonitorHistoryQuery) GroupBy(field string, fields ...string) *C // Example: // // var v []struct { -// DeletedAt time.Time `json:"deleted_at,omitempty"` +// MonitorID int64 `json:"monitor_id,omitempty"` // } // // client.ChannelMonitorHistory.Query(). -// Select(channelmonitorhistory.FieldDeletedAt). +// Select(channelmonitorhistory.FieldMonitorID). // Scan(ctx, &v) func (_q *ChannelMonitorHistoryQuery) Select(fields ...string) *ChannelMonitorHistorySelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) diff --git a/backend/ent/channelmonitorhistory_update.go b/backend/ent/channelmonitorhistory_update.go index 85193ec1..a85a8072 100644 --- a/backend/ent/channelmonitorhistory_update.go +++ b/backend/ent/channelmonitorhistory_update.go @@ -29,26 +29,6 @@ func (_u *ChannelMonitorHistoryUpdate) Where(ps ...predicate.ChannelMonitorHisto return _u } -// SetDeletedAt sets the "deleted_at" field. -func (_u *ChannelMonitorHistoryUpdate) SetDeletedAt(v time.Time) *ChannelMonitorHistoryUpdate { - _u.mutation.SetDeletedAt(v) - return _u -} - -// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. -func (_u *ChannelMonitorHistoryUpdate) SetNillableDeletedAt(v *time.Time) *ChannelMonitorHistoryUpdate { - if v != nil { - _u.SetDeletedAt(*v) - } - return _u -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (_u *ChannelMonitorHistoryUpdate) ClearDeletedAt() *ChannelMonitorHistoryUpdate { - _u.mutation.ClearDeletedAt() - return _u -} - // SetMonitorID sets the "monitor_id" field. func (_u *ChannelMonitorHistoryUpdate) SetMonitorID(v int64) *ChannelMonitorHistoryUpdate { _u.mutation.SetMonitorID(v) @@ -257,12 +237,6 @@ func (_u *ChannelMonitorHistoryUpdate) sqlSave(ctx context.Context) (_node int, } } } - if value, ok := _u.mutation.DeletedAt(); ok { - _spec.SetField(channelmonitorhistory.FieldDeletedAt, field.TypeTime, value) - } - if _u.mutation.DeletedAtCleared() { - _spec.ClearField(channelmonitorhistory.FieldDeletedAt, field.TypeTime) - } if value, ok := _u.mutation.Model(); ok { _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value) } @@ -345,26 +319,6 @@ type ChannelMonitorHistoryUpdateOne struct { mutation *ChannelMonitorHistoryMutation } -// SetDeletedAt sets the "deleted_at" field. -func (_u *ChannelMonitorHistoryUpdateOne) SetDeletedAt(v time.Time) *ChannelMonitorHistoryUpdateOne { - _u.mutation.SetDeletedAt(v) - return _u -} - -// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. -func (_u *ChannelMonitorHistoryUpdateOne) SetNillableDeletedAt(v *time.Time) *ChannelMonitorHistoryUpdateOne { - if v != nil { - _u.SetDeletedAt(*v) - } - return _u -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (_u *ChannelMonitorHistoryUpdateOne) ClearDeletedAt() *ChannelMonitorHistoryUpdateOne { - _u.mutation.ClearDeletedAt() - return _u -} - // SetMonitorID sets the "monitor_id" field. func (_u *ChannelMonitorHistoryUpdateOne) SetMonitorID(v int64) *ChannelMonitorHistoryUpdateOne { _u.mutation.SetMonitorID(v) @@ -603,12 +557,6 @@ func (_u *ChannelMonitorHistoryUpdateOne) sqlSave(ctx context.Context) (_node *C } } } - if value, ok := _u.mutation.DeletedAt(); ok { - _spec.SetField(channelmonitorhistory.FieldDeletedAt, field.TypeTime, value) - } - if _u.mutation.DeletedAtCleared() { - _spec.ClearField(channelmonitorhistory.FieldDeletedAt, field.TypeTime) - } if value, ok := _u.mutation.Model(); ok { _spec.SetField(channelmonitorhistory.FieldModel, field.TypeString, value) } diff --git a/backend/ent/client.go b/backend/ent/client.go index ca208094..ebc7fc5e 100644 --- a/backend/ent/client.go +++ b/backend/ent/client.go @@ -1912,14 +1912,12 @@ func (c *ChannelMonitorDailyRollupClient) QueryMonitor(_m *ChannelMonitorDailyRo // Hooks returns the client hooks. func (c *ChannelMonitorDailyRollupClient) Hooks() []Hook { - hooks := c.hooks.ChannelMonitorDailyRollup - return append(hooks[:len(hooks):len(hooks)], channelmonitordailyrollup.Hooks[:]...) + return c.hooks.ChannelMonitorDailyRollup } // Interceptors returns the client interceptors. func (c *ChannelMonitorDailyRollupClient) Interceptors() []Interceptor { - inters := c.inters.ChannelMonitorDailyRollup - return append(inters[:len(inters):len(inters)], channelmonitordailyrollup.Interceptors[:]...) + return c.inters.ChannelMonitorDailyRollup } func (c *ChannelMonitorDailyRollupClient) mutate(ctx context.Context, m *ChannelMonitorDailyRollupMutation) (Value, error) { @@ -2063,14 +2061,12 @@ func (c *ChannelMonitorHistoryClient) QueryMonitor(_m *ChannelMonitorHistory) *C // Hooks returns the client hooks. func (c *ChannelMonitorHistoryClient) Hooks() []Hook { - hooks := c.hooks.ChannelMonitorHistory - return append(hooks[:len(hooks):len(hooks)], channelmonitorhistory.Hooks[:]...) + return c.hooks.ChannelMonitorHistory } // Interceptors returns the client interceptors. func (c *ChannelMonitorHistoryClient) Interceptors() []Interceptor { - inters := c.inters.ChannelMonitorHistory - return append(inters[:len(inters):len(inters)], channelmonitorhistory.Interceptors[:]...) + return c.inters.ChannelMonitorHistory } func (c *ChannelMonitorHistoryClient) mutate(ctx context.Context, m *ChannelMonitorHistoryMutation) (Value, error) { diff --git a/backend/ent/migrate/schema.go b/backend/ent/migrate/schema.go index 9ce914a3..dba43ddf 100644 --- a/backend/ent/migrate/schema.go +++ b/backend/ent/migrate/schema.go @@ -464,7 +464,6 @@ var ( // ChannelMonitorDailyRollupsColumns holds the columns for the "channel_monitor_daily_rollups" table. ChannelMonitorDailyRollupsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, - {Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}}, {Name: "model", Type: field.TypeString, Size: 200}, {Name: "bucket_date", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "date"}}, {Name: "total_checks", Type: field.TypeInt, Default: 0}, @@ -488,7 +487,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "channel_monitor_daily_rollups_channel_monitors_daily_rollups", - Columns: []*schema.Column{ChannelMonitorDailyRollupsColumns[15]}, + Columns: []*schema.Column{ChannelMonitorDailyRollupsColumns[14]}, RefColumns: []*schema.Column{ChannelMonitorsColumns[0]}, OnDelete: schema.Cascade, }, @@ -497,19 +496,18 @@ var ( { Name: "channelmonitordailyrollup_monitor_id_model_bucket_date", Unique: true, - Columns: []*schema.Column{ChannelMonitorDailyRollupsColumns[15], ChannelMonitorDailyRollupsColumns[2], ChannelMonitorDailyRollupsColumns[3]}, + Columns: []*schema.Column{ChannelMonitorDailyRollupsColumns[14], ChannelMonitorDailyRollupsColumns[1], ChannelMonitorDailyRollupsColumns[2]}, }, { Name: "channelmonitordailyrollup_bucket_date", Unique: false, - Columns: []*schema.Column{ChannelMonitorDailyRollupsColumns[3]}, + Columns: []*schema.Column{ChannelMonitorDailyRollupsColumns[2]}, }, }, } // ChannelMonitorHistoriesColumns holds the columns for the "channel_monitor_histories" table. ChannelMonitorHistoriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, - {Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}}, {Name: "model", Type: field.TypeString, Size: 200}, {Name: "status", Type: field.TypeEnum, Enums: []string{"operational", "degraded", "failed", "error"}}, {Name: "latency_ms", Type: field.TypeInt, Nullable: true}, @@ -526,7 +524,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "channel_monitor_histories_channel_monitors_history", - Columns: []*schema.Column{ChannelMonitorHistoriesColumns[8]}, + Columns: []*schema.Column{ChannelMonitorHistoriesColumns[7]}, RefColumns: []*schema.Column{ChannelMonitorsColumns[0]}, OnDelete: schema.Cascade, }, @@ -535,12 +533,12 @@ var ( { Name: "channelmonitorhistory_monitor_id_model_checked_at", Unique: false, - Columns: []*schema.Column{ChannelMonitorHistoriesColumns[8], ChannelMonitorHistoriesColumns[2], ChannelMonitorHistoriesColumns[7]}, + Columns: []*schema.Column{ChannelMonitorHistoriesColumns[7], ChannelMonitorHistoriesColumns[1], ChannelMonitorHistoriesColumns[6]}, }, { Name: "channelmonitorhistory_checked_at", Unique: false, - Columns: []*schema.Column{ChannelMonitorHistoriesColumns[7]}, + Columns: []*schema.Column{ChannelMonitorHistoriesColumns[6]}, }, }, } diff --git a/backend/ent/mutation.go b/backend/ent/mutation.go index e97456fe..43e52371 100644 --- a/backend/ent/mutation.go +++ b/backend/ent/mutation.go @@ -10022,7 +10022,6 @@ type ChannelMonitorDailyRollupMutation struct { op Op typ string id *int64 - deleted_at *time.Time model *string bucket_date *time.Time total_checks *int @@ -10152,55 +10151,6 @@ func (m *ChannelMonitorDailyRollupMutation) IDs(ctx context.Context) ([]int64, e } } -// SetDeletedAt sets the "deleted_at" field. -func (m *ChannelMonitorDailyRollupMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t -} - -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChannelMonitorDailyRollupMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at - if v == nil { - return - } - return *v, true -} - -// OldDeletedAt returns the old "deleted_at" field's value of the ChannelMonitorDailyRollup entity. -// If the ChannelMonitorDailyRollup 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 *ChannelMonitorDailyRollupMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeletedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) - } - return oldValue.DeletedAt, nil -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChannelMonitorDailyRollupMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[channelmonitordailyrollup.FieldDeletedAt] = struct{}{} -} - -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChannelMonitorDailyRollupMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[channelmonitordailyrollup.FieldDeletedAt] - return ok -} - -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChannelMonitorDailyRollupMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, channelmonitordailyrollup.FieldDeletedAt) -} - // SetMonitorID sets the "monitor_id" field. func (m *ChannelMonitorDailyRollupMutation) SetMonitorID(i int64) { m.monitor = &i @@ -10966,10 +10916,7 @@ func (m *ChannelMonitorDailyRollupMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ChannelMonitorDailyRollupMutation) Fields() []string { - fields := make([]string, 0, 15) - if m.deleted_at != nil { - fields = append(fields, channelmonitordailyrollup.FieldDeletedAt) - } + fields := make([]string, 0, 14) if m.monitor != nil { fields = append(fields, channelmonitordailyrollup.FieldMonitorID) } @@ -11020,8 +10967,6 @@ func (m *ChannelMonitorDailyRollupMutation) Fields() []string { // schema. func (m *ChannelMonitorDailyRollupMutation) Field(name string) (ent.Value, bool) { switch name { - case channelmonitordailyrollup.FieldDeletedAt: - return m.DeletedAt() case channelmonitordailyrollup.FieldMonitorID: return m.MonitorID() case channelmonitordailyrollup.FieldModel: @@ -11059,8 +11004,6 @@ func (m *ChannelMonitorDailyRollupMutation) Field(name string) (ent.Value, bool) // database failed. func (m *ChannelMonitorDailyRollupMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case channelmonitordailyrollup.FieldDeletedAt: - return m.OldDeletedAt(ctx) case channelmonitordailyrollup.FieldMonitorID: return m.OldMonitorID(ctx) case channelmonitordailyrollup.FieldModel: @@ -11098,13 +11041,6 @@ func (m *ChannelMonitorDailyRollupMutation) OldField(ctx context.Context, name s // type. func (m *ChannelMonitorDailyRollupMutation) SetField(name string, value ent.Value) error { switch name { - case channelmonitordailyrollup.FieldDeletedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeletedAt(v) - return nil case channelmonitordailyrollup.FieldMonitorID: v, ok := value.(int64) if !ok { @@ -11355,11 +11291,7 @@ func (m *ChannelMonitorDailyRollupMutation) AddField(name string, value ent.Valu // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ChannelMonitorDailyRollupMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(channelmonitordailyrollup.FieldDeletedAt) { - fields = append(fields, channelmonitordailyrollup.FieldDeletedAt) - } - return fields + return nil } // FieldCleared returns a boolean indicating if a field with the given name was @@ -11372,11 +11304,6 @@ func (m *ChannelMonitorDailyRollupMutation) 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 *ChannelMonitorDailyRollupMutation) ClearField(name string) error { - switch name { - case channelmonitordailyrollup.FieldDeletedAt: - m.ClearDeletedAt() - return nil - } return fmt.Errorf("unknown ChannelMonitorDailyRollup nullable field %s", name) } @@ -11384,9 +11311,6 @@ func (m *ChannelMonitorDailyRollupMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *ChannelMonitorDailyRollupMutation) ResetField(name string) error { switch name { - case channelmonitordailyrollup.FieldDeletedAt: - m.ResetDeletedAt() - return nil case channelmonitordailyrollup.FieldMonitorID: m.ResetMonitorID() return nil @@ -11513,7 +11437,6 @@ type ChannelMonitorHistoryMutation struct { op Op typ string id *int64 - deleted_at *time.Time model *string status *channelmonitorhistory.Status latency_ms *int @@ -11628,55 +11551,6 @@ func (m *ChannelMonitorHistoryMutation) IDs(ctx context.Context) ([]int64, error } } -// SetDeletedAt sets the "deleted_at" field. -func (m *ChannelMonitorHistoryMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t -} - -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChannelMonitorHistoryMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at - if v == nil { - return - } - return *v, true -} - -// OldDeletedAt returns the old "deleted_at" field's value of the ChannelMonitorHistory entity. -// If the ChannelMonitorHistory 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 *ChannelMonitorHistoryMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeletedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) - } - return oldValue.DeletedAt, nil -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChannelMonitorHistoryMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[channelmonitorhistory.FieldDeletedAt] = struct{}{} -} - -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChannelMonitorHistoryMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[channelmonitorhistory.FieldDeletedAt] - return ok -} - -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChannelMonitorHistoryMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, channelmonitorhistory.FieldDeletedAt) -} - // SetMonitorID sets the "monitor_id" field. func (m *ChannelMonitorHistoryMutation) SetMonitorID(i int64) { m.monitor = &i @@ -12071,10 +11945,7 @@ func (m *ChannelMonitorHistoryMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ChannelMonitorHistoryMutation) Fields() []string { - fields := make([]string, 0, 8) - if m.deleted_at != nil { - fields = append(fields, channelmonitorhistory.FieldDeletedAt) - } + fields := make([]string, 0, 7) if m.monitor != nil { fields = append(fields, channelmonitorhistory.FieldMonitorID) } @@ -12104,8 +11975,6 @@ func (m *ChannelMonitorHistoryMutation) Fields() []string { // schema. func (m *ChannelMonitorHistoryMutation) Field(name string) (ent.Value, bool) { switch name { - case channelmonitorhistory.FieldDeletedAt: - return m.DeletedAt() case channelmonitorhistory.FieldMonitorID: return m.MonitorID() case channelmonitorhistory.FieldModel: @@ -12129,8 +11998,6 @@ func (m *ChannelMonitorHistoryMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *ChannelMonitorHistoryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case channelmonitorhistory.FieldDeletedAt: - return m.OldDeletedAt(ctx) case channelmonitorhistory.FieldMonitorID: return m.OldMonitorID(ctx) case channelmonitorhistory.FieldModel: @@ -12154,13 +12021,6 @@ func (m *ChannelMonitorHistoryMutation) OldField(ctx context.Context, name strin // type. func (m *ChannelMonitorHistoryMutation) SetField(name string, value ent.Value) error { switch name { - case channelmonitorhistory.FieldDeletedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeletedAt(v) - return nil case channelmonitorhistory.FieldMonitorID: v, ok := value.(int64) if !ok { @@ -12267,9 +12127,6 @@ func (m *ChannelMonitorHistoryMutation) AddField(name string, value ent.Value) e // mutation. func (m *ChannelMonitorHistoryMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(channelmonitorhistory.FieldDeletedAt) { - fields = append(fields, channelmonitorhistory.FieldDeletedAt) - } if m.FieldCleared(channelmonitorhistory.FieldLatencyMs) { fields = append(fields, channelmonitorhistory.FieldLatencyMs) } @@ -12293,9 +12150,6 @@ func (m *ChannelMonitorHistoryMutation) FieldCleared(name string) bool { // error if the field is not defined in the schema. func (m *ChannelMonitorHistoryMutation) ClearField(name string) error { switch name { - case channelmonitorhistory.FieldDeletedAt: - m.ClearDeletedAt() - return nil case channelmonitorhistory.FieldLatencyMs: m.ClearLatencyMs() return nil @@ -12313,9 +12167,6 @@ func (m *ChannelMonitorHistoryMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *ChannelMonitorHistoryMutation) ResetField(name string) error { switch name { - case channelmonitorhistory.FieldDeletedAt: - m.ResetDeletedAt() - return nil case channelmonitorhistory.FieldMonitorID: m.ResetMonitorID() return nil diff --git a/backend/ent/runtime/runtime.go b/backend/ent/runtime/runtime.go index 25076444..63552bb5 100644 --- a/backend/ent/runtime/runtime.go +++ b/backend/ent/runtime/runtime.go @@ -521,11 +521,6 @@ func init() { channelmonitorDescIntervalSeconds := channelmonitorFields[8].Descriptor() // channelmonitor.IntervalSecondsValidator is a validator for the "interval_seconds" field. It is called by the builders before save. channelmonitor.IntervalSecondsValidator = channelmonitorDescIntervalSeconds.Validators[0].(func(int) error) - channelmonitordailyrollupMixin := schema.ChannelMonitorDailyRollup{}.Mixin() - channelmonitordailyrollupMixinHooks0 := channelmonitordailyrollupMixin[0].Hooks() - channelmonitordailyrollup.Hooks[0] = channelmonitordailyrollupMixinHooks0[0] - channelmonitordailyrollupMixinInters0 := channelmonitordailyrollupMixin[0].Interceptors() - channelmonitordailyrollup.Interceptors[0] = channelmonitordailyrollupMixinInters0[0] channelmonitordailyrollupFields := schema.ChannelMonitorDailyRollup{}.Fields() _ = channelmonitordailyrollupFields // channelmonitordailyrollupDescModel is the schema descriptor for model field. @@ -592,11 +587,6 @@ func init() { channelmonitordailyrollup.DefaultComputedAt = channelmonitordailyrollupDescComputedAt.Default.(func() time.Time) // channelmonitordailyrollup.UpdateDefaultComputedAt holds the default value on update for the computed_at field. channelmonitordailyrollup.UpdateDefaultComputedAt = channelmonitordailyrollupDescComputedAt.UpdateDefault.(func() time.Time) - channelmonitorhistoryMixin := schema.ChannelMonitorHistory{}.Mixin() - channelmonitorhistoryMixinHooks0 := channelmonitorhistoryMixin[0].Hooks() - channelmonitorhistory.Hooks[0] = channelmonitorhistoryMixinHooks0[0] - channelmonitorhistoryMixinInters0 := channelmonitorhistoryMixin[0].Interceptors() - channelmonitorhistory.Interceptors[0] = channelmonitorhistoryMixinInters0[0] channelmonitorhistoryFields := schema.ChannelMonitorHistory{}.Fields() _ = channelmonitorhistoryFields // channelmonitorhistoryDescModel is the schema descriptor for model field. diff --git a/backend/ent/schema/channel_monitor_daily_rollup.go b/backend/ent/schema/channel_monitor_daily_rollup.go index 574a28d9..23f032e3 100644 --- a/backend/ent/schema/channel_monitor_daily_rollup.go +++ b/backend/ent/schema/channel_monitor_daily_rollup.go @@ -10,13 +10,12 @@ import ( "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" - - "github.com/Wei-Shaw/sub2api/ent/schema/mixins" ) // ChannelMonitorDailyRollup 按 (monitor_id, model, bucket_date) 维度聚合的渠道监控日统计。 // 每天的明细被收敛为一行(保留 status 分布 + 延迟和),用于 7d/15d/30d 窗口的可用率 // 加权计算(avg_latency = sum_latency_ms / count_latency;availability = ok_count / total_checks)。 +// 超过保留期由每日维护任务分批物理删(不用软删除,理由同 channel_monitor_history)。 type ChannelMonitorDailyRollup struct { ent.Schema } @@ -27,12 +26,6 @@ func (ChannelMonitorDailyRollup) Annotations() []schema.Annotation { } } -func (ChannelMonitorDailyRollup) Mixin() []ent.Mixin { - return []ent.Mixin{ - mixins.SoftDeleteMixin{}, - } -} - func (ChannelMonitorDailyRollup) Fields() []ent.Field { return []ent.Field{ field.Int64("monitor_id"), diff --git a/backend/ent/schema/channel_monitor_history.go b/backend/ent/schema/channel_monitor_history.go index ec54b34f..4366e79a 100644 --- a/backend/ent/schema/channel_monitor_history.go +++ b/backend/ent/schema/channel_monitor_history.go @@ -9,13 +9,12 @@ import ( "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" - - "github.com/Wei-Shaw/sub2api/ent/schema/mixins" ) // ChannelMonitorHistory holds the schema definition for the ChannelMonitorHistory entity. -// 渠道监控历史:每次检测每个模型一行记录。明细只保留 1 天,超过 1 天的数据被聚合到 -// channel_monitor_daily_rollups 后软删(deleted_at),由后续懒清理任务物理移除。 +// 渠道监控历史:每次检测每个模型一行记录。明细只保留 1 天,超过 1 天由每日维护任务 +// 先聚合到 channel_monitor_daily_rollups,再分批物理删(不用软删除:日志类表无恢复 +// 需求,软删会让行和索引只增不减,徒增磁盘和查询开销)。 type ChannelMonitorHistory struct { ent.Schema } @@ -26,12 +25,6 @@ func (ChannelMonitorHistory) Annotations() []schema.Annotation { } } -func (ChannelMonitorHistory) Mixin() []ent.Mixin { - return []ent.Mixin{ - mixins.SoftDeleteMixin{}, - } -} - func (ChannelMonitorHistory) Fields() []ent.Field { return []ent.Field{ field.Int64("monitor_id"), diff --git a/backend/internal/repository/channel_monitor_repo.go b/backend/internal/repository/channel_monitor_repo.go index badbdbca..f4e2a0ec 100644 --- a/backend/internal/repository/channel_monitor_repo.go +++ b/backend/internal/repository/channel_monitor_repo.go @@ -9,7 +9,6 @@ import ( dbent "github.com/Wei-Shaw/sub2api/ent" "github.com/Wei-Shaw/sub2api/ent/channelmonitor" - "github.com/Wei-Shaw/sub2api/ent/channelmonitordailyrollup" "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory" "github.com/Wei-Shaw/sub2api/internal/service" "github.com/lib/pq" @@ -195,15 +194,10 @@ func (r *channelMonitorRepository) InsertHistoryBatch(ctx context.Context, rows return nil } +// DeleteHistoryBefore 物理删 checked_at < before 的明细,分批 channelMonitorPruneBatchSize 行一批, +// 避免单事务删除过多引起锁/WAL 压力。借助 (checked_at) 索引定位小批 id,再按 id 删。 func (r *channelMonitorRepository) DeleteHistoryBefore(ctx context.Context, before time.Time) (int64, error) { - client := clientFromContext(ctx, r.client) - n, err := client.ChannelMonitorHistory.Delete(). - Where(channelmonitorhistory.CheckedAtLT(before)). - Exec(ctx) - if err != nil { - return 0, fmt.Errorf("delete history before: %w", err) - } - return int64(n), nil + return deleteChannelMonitorBatched(ctx, r.db, channelMonitorPruneHistorySQL, before) } // ListHistory 按 checked_at 倒序返回某个监控的最近 N 条历史记录。 @@ -247,7 +241,6 @@ func (r *channelMonitorRepository) ListLatestPerModel(ctx context.Context, monit model, status, latency_ms, ping_latency_ms, checked_at FROM channel_monitor_histories WHERE monitor_id = $1 - AND deleted_at IS NULL ORDER BY model, checked_at DESC ` rows, err := r.db.QueryContext(ctx, q, monitorID) @@ -302,7 +295,6 @@ func (r *channelMonitorRepository) ComputeAvailability(ctx context.Context, moni COUNT(latency_ms) AS count_latency FROM channel_monitor_histories WHERE monitor_id = $1 - AND deleted_at IS NULL AND checked_at >= CURRENT_DATE GROUP BY model ), @@ -310,7 +302,6 @@ func (r *channelMonitorRepository) ComputeAvailability(ctx context.Context, moni SELECT model, total_checks, ok_count, sum_latency_ms, count_latency FROM channel_monitor_daily_rollups WHERE monitor_id = $1 - AND deleted_at IS NULL AND bucket_date >= (CURRENT_DATE - $2::int) AND bucket_date < CURRENT_DATE ) @@ -376,7 +367,6 @@ func (r *channelMonitorRepository) ListLatestForMonitorIDs(ctx context.Context, monitor_id, model, status, latency_ms, ping_latency_ms, checked_at FROM channel_monitor_histories WHERE monitor_id = ANY($1) - AND deleted_at IS NULL ORDER BY monitor_id, model, checked_at DESC ` rows, err := r.db.QueryContext(ctx, q, pq.Array(ids)) @@ -437,7 +427,6 @@ func (r *channelMonitorRepository) ListRecentHistoryForMonitors( FROM channel_monitor_histories h JOIN targets t ON t.monitor_id = h.monitor_id AND t.model = h.model - WHERE h.deleted_at IS NULL ) SELECT monitor_id, status, latency_ms, ping_latency_ms, checked_at FROM ranked @@ -524,7 +513,6 @@ func (r *channelMonitorRepository) ComputeAvailabilityForMonitors(ctx context.Co COUNT(latency_ms) AS count_latency FROM channel_monitor_histories WHERE monitor_id = ANY($1) - AND deleted_at IS NULL AND checked_at >= CURRENT_DATE GROUP BY monitor_id, model ), @@ -532,7 +520,6 @@ func (r *channelMonitorRepository) ComputeAvailabilityForMonitors(ctx context.Co SELECT monitor_id, model, total_checks, ok_count, sum_latency_ms, count_latency FROM channel_monitor_daily_rollups WHERE monitor_id = ANY($1) - AND deleted_at IS NULL AND bucket_date >= (CURRENT_DATE - $2::int) AND bucket_date < CURRENT_DATE ) @@ -572,11 +559,10 @@ func (r *channelMonitorRepository) ComputeAvailabilityForMonitors(ctx context.Co // ---------- 聚合维护 ---------- -// UpsertDailyRollupsFor 把 targetDate 当天([targetDate, targetDate+1d))未软删的明细 +// UpsertDailyRollupsFor 把 targetDate 当天([targetDate, targetDate+1d))的明细 // 按 (monitor_id, model, bucket_date) 聚合写入 channel_monitor_daily_rollups。 // - 用 ON CONFLICT (monitor_id, model, bucket_date) DO UPDATE 实现幂等回填, // 重复执行只会用最新统计覆盖; -// - 同时把 deleted_at 重置为 NULL,避免历史误删后聚合行被持续过滤掉; // - $1::date 让 PG 自动把入参 truncate 到 UTC 日期,调用方不需要预处理 targetDate。 func (r *channelMonitorRepository) UpsertDailyRollupsFor(ctx context.Context, targetDate time.Time) (int64, error) { const q = ` @@ -604,8 +590,7 @@ func (r *channelMonitorRepository) UpsertDailyRollupsFor(ctx context.Context, ta COUNT(ping_latency_ms) AS count_ping_latency, NOW() FROM channel_monitor_histories - WHERE deleted_at IS NULL - AND checked_at >= $1::date + WHERE checked_at >= $1::date AND checked_at < ($1::date + INTERVAL '1 day') GROUP BY monitor_id, model ON CONFLICT (monitor_id, model, bucket_date) DO UPDATE SET @@ -619,8 +604,7 @@ func (r *channelMonitorRepository) UpsertDailyRollupsFor(ctx context.Context, ta count_latency = EXCLUDED.count_latency, sum_ping_latency_ms = EXCLUDED.sum_ping_latency_ms, count_ping_latency = EXCLUDED.count_ping_latency, - computed_at = NOW(), - deleted_at = NULL + computed_at = NOW() ` res, err := r.db.ExecContext(ctx, q, targetDate) if err != nil { @@ -633,17 +617,59 @@ func (r *channelMonitorRepository) UpsertDailyRollupsFor(ctx context.Context, ta return n, nil } -// DeleteRollupsBefore 软删 bucket_date < beforeDate 的聚合行。 -// 走 ent client,利用 SoftDeleteMixin 把 DELETE 自动改写为 UPDATE deleted_at = NOW()。 +// DeleteRollupsBefore 物理删 bucket_date < beforeDate 的聚合行,同样分批。 func (r *channelMonitorRepository) DeleteRollupsBefore(ctx context.Context, beforeDate time.Time) (int64, error) { - client := clientFromContext(ctx, r.client) - n, err := client.ChannelMonitorDailyRollup.Delete(). - Where(channelmonitordailyrollup.BucketDateLT(beforeDate)). - Exec(ctx) - if err != nil { - return 0, fmt.Errorf("delete rollups before: %w", err) + return deleteChannelMonitorBatched(ctx, r.db, channelMonitorPruneRollupSQL, beforeDate) +} + +// channelMonitorPruneBatchSize 单批删除上限。与 ops_cleanup_service 保持一致的 5000, +// 在大表上按 id 小批删可以避免长事务和 WAL 堆积。 +const channelMonitorPruneBatchSize = 5000 + +// channelMonitorPruneHistorySQL 分批物理删明细表过期行。 +const channelMonitorPruneHistorySQL = ` +WITH batch AS ( + SELECT id FROM channel_monitor_histories + WHERE checked_at < $1 + ORDER BY id + LIMIT $2 +) +DELETE FROM channel_monitor_histories +WHERE id IN (SELECT id FROM batch) +` + +// channelMonitorPruneRollupSQL 分批物理删 rollup 表过期行。bucket_date 需要 ::date 转型 +// 保证与 DATE 列一致比较。 +const channelMonitorPruneRollupSQL = ` +WITH batch AS ( + SELECT id FROM channel_monitor_daily_rollups + WHERE bucket_date < $1::date + ORDER BY id + LIMIT $2 +) +DELETE FROM channel_monitor_daily_rollups +WHERE id IN (SELECT id FROM batch) +` + +// deleteChannelMonitorBatched 循环执行分批 DELETE,直到影响行为 0。返回累计删除行数。 +// cutoff 由调用方按列类型传入(明细用 time.Time 对 TIMESTAMPTZ,rollup 用 time.Time SQL 侧 ::date 转型)。 +func deleteChannelMonitorBatched(ctx context.Context, db *sql.DB, query string, cutoff time.Time) (int64, error) { + var total int64 + for { + res, err := db.ExecContext(ctx, query, cutoff, channelMonitorPruneBatchSize) + if err != nil { + return total, fmt.Errorf("channel_monitor prune batch: %w", err) + } + affected, err := res.RowsAffected() + if err != nil { + return total, fmt.Errorf("channel_monitor prune rows affected: %w", err) + } + total += affected + if affected == 0 { + break + } } - return int64(n), nil + return total, nil } // LoadAggregationWatermark 读 watermark 表(id=1)。 diff --git a/backend/migrations/127_drop_channel_monitor_deleted_at.sql b/backend/migrations/127_drop_channel_monitor_deleted_at.sql new file mode 100644 index 00000000..2260f06b --- /dev/null +++ b/backend/migrations/127_drop_channel_monitor_deleted_at.sql @@ -0,0 +1,16 @@ +-- Migration: 127_drop_channel_monitor_deleted_at +-- 纠正 110 引入的 SoftDeleteMixin:日志/聚合表无恢复需求,软删会让行和索引只增不减, +-- 徒增磁盘和查询开销。改回分批物理删(由 OpsCleanupService 每天凌晨统一调度, +-- deleteOldRowsByID 模板,batch=5000)。 +-- +-- 110 尚未跑过聚合/清理(首次 maintenance 在次日 02:00),所以此处不担心业务数据。 +-- 直接 DROP 列 + 索引;对应的 Go 侧 ent schema 已移除 SoftDeleteMixin、repo 的 +-- raw SQL 已移除 deleted_at IS NULL 过滤。 + +DROP INDEX IF EXISTS idx_channel_monitor_histories_deleted_at; +ALTER TABLE channel_monitor_histories + DROP COLUMN IF EXISTS deleted_at; + +DROP INDEX IF EXISTS idx_channel_monitor_daily_rollups_deleted_at; +ALTER TABLE channel_monitor_daily_rollups + DROP COLUMN IF EXISTS deleted_at; diff --git a/frontend/src/components/layout/AppSidebar.vue b/frontend/src/components/layout/AppSidebar.vue index 8b9fbdea..248e0021 100644 --- a/frontend/src/components/layout/AppSidebar.vue +++ b/frontend/src/components/layout/AppSidebar.vue @@ -199,6 +199,28 @@ interface NavItem { * does NOT navigate to its `path`. The `path` is purely a stable key. */ expandOnly?: boolean + /** + * 可选的功能开关 getter。返回 false 时菜单项被隐藏;返回 undefined/true 时显示。 + * 宽容策略(undefined → 显示)避免 public settings 未加载完成时菜单闪烁消失。 + * Getter 里访问的 reactive 来源(store / composable)会被 computed 自动追踪, + * 开关切换时菜单自动更新。 + */ + featureFlag?: () => boolean | undefined +} + +// applyFeatureFlags 递归过滤掉 featureFlag() === false 的节点(含子节点)。 +// 使用 `!== false` 宽容语义:undefined(设置未加载)或 true 都视为显示。 +function applyFeatureFlags(items: NavItem[]): NavItem[] { + const out: NavItem[] = [] + for (const item of items) { + if (item.featureFlag && item.featureFlag() === false) continue + if (item.children) { + out.push({ ...item, children: applyFeatureFlags(item.children) }) + } else { + out.push(item) + } + } + return out } const { t } = useI18n() @@ -605,36 +627,27 @@ const ChevronDownIcon = { ) } -// User navigation items (for regular users) -const userNavItems = computed((): NavItem[] => { - const items: NavItem[] = [ - { path: '/dashboard', label: t('nav.dashboard'), icon: DashboardIcon }, +// 各个开关集中声明:所有菜单项引用这里的 getter,未来加新开关只需在此加一个常量。 +// getter 返回 false = 隐藏;undefined/true = 显示(宽容策略,避免 public settings 未加载闪烁)。 +const flagChannelMonitor = () => appStore.cachedPublicSettings?.channel_monitor_enabled +const flagPayment = () => appStore.cachedPublicSettings?.payment_enabled +const flagOpsMonitoring = () => adminSettingsStore.opsMonitoringEnabled +const flagAdminPayment = () => adminSettingsStore.paymentEnabled + +// buildSelfNavItems 构造用户自己的导航项(用户端主菜单和管理员的"我的账户"子菜单共享这组声明)。 +// withDashboard=true 时包含仪表盘(用户端),false 时不含(管理员的个人区已经有独立仪表盘入口)。 +function buildSelfNavItems(withDashboard: boolean): NavItem[] { + const items: NavItem[] = [] + if (withDashboard) { + items.push({ path: '/dashboard', label: t('nav.dashboard'), icon: DashboardIcon }) + } + items.push( { path: '/keys', label: t('nav.apiKeys'), icon: KeyIcon }, { path: '/usage', label: t('nav.usage'), icon: ChartIcon, hideInSimpleMode: true }, - ...(appStore.cachedPublicSettings?.channel_monitor_enabled - ? [{ path: '/monitor', label: t('nav.channelStatus'), icon: SignalIcon }] - : []), + { path: '/monitor', label: t('nav.channelStatus'), icon: SignalIcon, featureFlag: flagChannelMonitor }, { path: '/subscriptions', label: t('nav.mySubscriptions'), icon: CreditCardIcon, hideInSimpleMode: true }, - ...(appStore.cachedPublicSettings?.payment_enabled - ? [ - { - path: '/purchase', - label: t('nav.buySubscription'), - icon: RechargeSubscriptionIcon, - hideInSimpleMode: true - }, - ] - : []), - ...(appStore.cachedPublicSettings?.payment_enabled - ? [ - { - path: '/orders', - label: t('nav.myOrders'), - icon: OrderListIcon, - hideInSimpleMode: true - }, - ] - : []), + { path: '/purchase', label: t('nav.buySubscription'), icon: RechargeSubscriptionIcon, hideInSimpleMode: true, featureFlag: flagPayment }, + { path: '/orders', label: t('nav.myOrders'), icon: OrderListIcon, hideInSimpleMode: true, featureFlag: flagPayment }, { path: '/redeem', label: t('nav.redeem'), icon: GiftIcon, hideInSimpleMode: true }, { path: '/profile', label: t('nav.profile'), icon: UserIcon }, ...customMenuItemsForUser.value.map((item): NavItem => ({ @@ -643,50 +656,21 @@ const userNavItems = computed((): NavItem[] => { icon: null, iconSvg: item.icon_svg, })), - ] - return authStore.isSimpleMode ? items.filter(item => !item.hideInSimpleMode) : items -}) + ) + return items +} + +// finalizeNav 合并三重过滤:featureFlag 过滤 + simple 模式过滤。 +function finalizeNav(items: NavItem[]): NavItem[] { + const visible = applyFeatureFlags(items) + return authStore.isSimpleMode ? visible.filter(item => !item.hideInSimpleMode) : visible +} + +// User navigation items (for regular users) +const userNavItems = computed((): NavItem[] => finalizeNav(buildSelfNavItems(true))) // Personal navigation items (for admin's "My Account" section, without Dashboard) -const personalNavItems = computed((): NavItem[] => { - const items: NavItem[] = [ - { path: '/keys', label: t('nav.apiKeys'), icon: KeyIcon }, - { path: '/usage', label: t('nav.usage'), icon: ChartIcon, hideInSimpleMode: true }, - ...(appStore.cachedPublicSettings?.channel_monitor_enabled - ? [{ path: '/monitor', label: t('nav.channelStatus'), icon: SignalIcon }] - : []), - { path: '/subscriptions', label: t('nav.mySubscriptions'), icon: CreditCardIcon, hideInSimpleMode: true }, - ...(appStore.cachedPublicSettings?.payment_enabled - ? [ - { - path: '/purchase', - label: t('nav.buySubscription'), - icon: RechargeSubscriptionIcon, - hideInSimpleMode: true - }, - ] - : []), - ...(appStore.cachedPublicSettings?.payment_enabled - ? [ - { - path: '/orders', - label: t('nav.myOrders'), - icon: OrderListIcon, - hideInSimpleMode: true - }, - ] - : []), - { path: '/redeem', label: t('nav.redeem'), icon: GiftIcon, hideInSimpleMode: true }, - { path: '/profile', label: t('nav.profile'), icon: UserIcon }, - ...customMenuItemsForUser.value.map((item): NavItem => ({ - path: `/custom/${item.id}`, - label: item.label, - icon: null, - iconSvg: item.icon_svg, - })), - ] - return authStore.isSimpleMode ? items.filter(item => !item.hideInSimpleMode) : items -}) +const personalNavItems = computed((): NavItem[] => finalizeNav(buildSelfNavItems(false))) // Custom menu items filtered by visibility const customMenuItemsForUser = computed(() => { @@ -706,9 +690,7 @@ const customMenuItemsForAdmin = computed(() => { const adminNavItems = computed((): NavItem[] => { const baseItems: NavItem[] = [ { path: '/admin/dashboard', label: t('nav.dashboard'), icon: DashboardIcon }, - ...(adminSettingsStore.opsMonitoringEnabled - ? [{ path: '/admin/ops', label: t('nav.ops'), icon: ChartIcon }] - : []), + { path: '/admin/ops', label: t('nav.ops'), icon: ChartIcon, featureFlag: flagOpsMonitoring }, { path: '/admin/users', label: t('nav.users'), icon: UsersIcon, hideInSimpleMode: true }, { path: '/admin/groups', label: t('nav.groups'), icon: FolderIcon, hideInSimpleMode: true }, { @@ -719,9 +701,7 @@ const adminNavItems = computed((): NavItem[] => { expandOnly: true, children: [ { path: '/admin/channels/pricing', label: t('nav.channelPricing'), icon: PriceTagIcon }, - ...(appStore.cachedPublicSettings?.channel_monitor_enabled - ? [{ path: '/admin/channels/monitor', label: t('nav.channelMonitor'), icon: SignalIcon }] - : []), + { path: '/admin/channels/monitor', label: t('nav.channelMonitor'), icon: SignalIcon, featureFlag: flagChannelMonitor }, ], }, { path: '/admin/subscriptions', label: t('nav.subscriptions'), icon: CreditCardIcon, hideInSimpleMode: true }, @@ -730,43 +710,40 @@ const adminNavItems = computed((): NavItem[] => { { path: '/admin/proxies', label: t('nav.proxies'), icon: ServerIcon }, { path: '/admin/redeem', label: t('nav.redeemCodes'), icon: TicketIcon, hideInSimpleMode: true }, { path: '/admin/promo-codes', label: t('nav.promoCodes'), icon: GiftIcon, hideInSimpleMode: true }, - ...(adminSettingsStore.paymentEnabled - ? [ - { - path: '/admin/orders', - label: t('nav.orderManagement'), - icon: OrderIcon, - hideInSimpleMode: true, - expandOnly: true, - children: [ - { path: '/admin/orders/dashboard', label: t('nav.paymentDashboard'), icon: ChartIcon }, - { path: '/admin/orders', label: t('nav.orderManagement'), icon: OrderIcon }, - { path: '/admin/orders/plans', label: t('nav.paymentPlans'), icon: CreditCardIcon }, - ], - }, - ] - : []), + { + path: '/admin/orders', + label: t('nav.orderManagement'), + icon: OrderIcon, + hideInSimpleMode: true, + expandOnly: true, + featureFlag: flagAdminPayment, + children: [ + { path: '/admin/orders/dashboard', label: t('nav.paymentDashboard'), icon: ChartIcon }, + { path: '/admin/orders', label: t('nav.orderManagement'), icon: OrderIcon }, + { path: '/admin/orders/plans', label: t('nav.paymentPlans'), icon: CreditCardIcon }, + ], + }, { path: '/admin/usage', label: t('nav.usage'), icon: ChartIcon } ] + const visible = applyFeatureFlags(baseItems) + // 简单模式下,在系统设置前插入 API密钥 if (authStore.isSimpleMode) { - const filtered = baseItems.filter(item => !item.hideInSimpleMode) + const filtered = visible.filter(item => !item.hideInSimpleMode) filtered.push({ path: '/keys', label: t('nav.apiKeys'), icon: KeyIcon }) filtered.push({ path: '/admin/settings', label: t('nav.settings'), icon: CogIcon }) - // Add admin custom menu items after settings for (const cm of customMenuItemsForAdmin.value) { filtered.push({ path: `/custom/${cm.id}`, label: cm.label, icon: null, iconSvg: cm.icon_svg }) } return filtered } - baseItems.push({ path: '/admin/settings', label: t('nav.settings'), icon: CogIcon }) - // Add admin custom menu items after settings + visible.push({ path: '/admin/settings', label: t('nav.settings'), icon: CogIcon }) for (const cm of customMenuItemsForAdmin.value) { - baseItems.push({ path: `/custom/${cm.id}`, label: cm.label, icon: null, iconSvg: cm.icon_svg }) + visible.push({ path: `/custom/${cm.id}`, label: cm.label, icon: null, iconSvg: cm.icon_svg }) } - return baseItems + return visible }) function toggleSidebar() {