feat(清理任务): 引入Ent存储并补充日志与测试
新增 usage_cleanup_task Ent schema 与仓储实现,支持清理任务排序分页 补充清理任务全链路日志、仪表盘重算触发及 UI 过滤调整 完善 repository/service 单测并引入 sqlite 测试依赖
This commit is contained in:
@@ -153,7 +153,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|||||||
updateService := service.ProvideUpdateService(updateCache, gitHubReleaseClient, serviceBuildInfo)
|
updateService := service.ProvideUpdateService(updateCache, gitHubReleaseClient, serviceBuildInfo)
|
||||||
systemHandler := handler.ProvideSystemHandler(updateService)
|
systemHandler := handler.ProvideSystemHandler(updateService)
|
||||||
adminSubscriptionHandler := admin.NewSubscriptionHandler(subscriptionService)
|
adminSubscriptionHandler := admin.NewSubscriptionHandler(subscriptionService)
|
||||||
usageCleanupRepository := repository.NewUsageCleanupRepository(db)
|
usageCleanupRepository := repository.NewUsageCleanupRepository(client, db)
|
||||||
usageCleanupService := service.ProvideUsageCleanupService(usageCleanupRepository, timingWheelService, dashboardAggregationService, configConfig)
|
usageCleanupService := service.ProvideUsageCleanupService(usageCleanupRepository, timingWheelService, dashboardAggregationService, configConfig)
|
||||||
adminUsageHandler := admin.NewUsageHandler(usageService, apiKeyService, adminService, usageCleanupService)
|
adminUsageHandler := admin.NewUsageHandler(usageService, apiKeyService, adminService, usageCleanupService)
|
||||||
userAttributeDefinitionRepository := repository.NewUserAttributeDefinitionRepository(client)
|
userAttributeDefinitionRepository := repository.NewUserAttributeDefinitionRepository(client)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/setting"
|
"github.com/Wei-Shaw/sub2api/ent/setting"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/user"
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
||||||
@@ -57,6 +58,8 @@ type Client struct {
|
|||||||
RedeemCode *RedeemCodeClient
|
RedeemCode *RedeemCodeClient
|
||||||
// Setting is the client for interacting with the Setting builders.
|
// Setting is the client for interacting with the Setting builders.
|
||||||
Setting *SettingClient
|
Setting *SettingClient
|
||||||
|
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
|
||||||
|
UsageCleanupTask *UsageCleanupTaskClient
|
||||||
// UsageLog is the client for interacting with the UsageLog builders.
|
// UsageLog is the client for interacting with the UsageLog builders.
|
||||||
UsageLog *UsageLogClient
|
UsageLog *UsageLogClient
|
||||||
// User is the client for interacting with the User builders.
|
// User is the client for interacting with the User builders.
|
||||||
@@ -89,6 +92,7 @@ func (c *Client) init() {
|
|||||||
c.Proxy = NewProxyClient(c.config)
|
c.Proxy = NewProxyClient(c.config)
|
||||||
c.RedeemCode = NewRedeemCodeClient(c.config)
|
c.RedeemCode = NewRedeemCodeClient(c.config)
|
||||||
c.Setting = NewSettingClient(c.config)
|
c.Setting = NewSettingClient(c.config)
|
||||||
|
c.UsageCleanupTask = NewUsageCleanupTaskClient(c.config)
|
||||||
c.UsageLog = NewUsageLogClient(c.config)
|
c.UsageLog = NewUsageLogClient(c.config)
|
||||||
c.User = NewUserClient(c.config)
|
c.User = NewUserClient(c.config)
|
||||||
c.UserAllowedGroup = NewUserAllowedGroupClient(c.config)
|
c.UserAllowedGroup = NewUserAllowedGroupClient(c.config)
|
||||||
@@ -196,6 +200,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|||||||
Proxy: NewProxyClient(cfg),
|
Proxy: NewProxyClient(cfg),
|
||||||
RedeemCode: NewRedeemCodeClient(cfg),
|
RedeemCode: NewRedeemCodeClient(cfg),
|
||||||
Setting: NewSettingClient(cfg),
|
Setting: NewSettingClient(cfg),
|
||||||
|
UsageCleanupTask: NewUsageCleanupTaskClient(cfg),
|
||||||
UsageLog: NewUsageLogClient(cfg),
|
UsageLog: NewUsageLogClient(cfg),
|
||||||
User: NewUserClient(cfg),
|
User: NewUserClient(cfg),
|
||||||
UserAllowedGroup: NewUserAllowedGroupClient(cfg),
|
UserAllowedGroup: NewUserAllowedGroupClient(cfg),
|
||||||
@@ -230,6 +235,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|||||||
Proxy: NewProxyClient(cfg),
|
Proxy: NewProxyClient(cfg),
|
||||||
RedeemCode: NewRedeemCodeClient(cfg),
|
RedeemCode: NewRedeemCodeClient(cfg),
|
||||||
Setting: NewSettingClient(cfg),
|
Setting: NewSettingClient(cfg),
|
||||||
|
UsageCleanupTask: NewUsageCleanupTaskClient(cfg),
|
||||||
UsageLog: NewUsageLogClient(cfg),
|
UsageLog: NewUsageLogClient(cfg),
|
||||||
User: NewUserClient(cfg),
|
User: NewUserClient(cfg),
|
||||||
UserAllowedGroup: NewUserAllowedGroupClient(cfg),
|
UserAllowedGroup: NewUserAllowedGroupClient(cfg),
|
||||||
@@ -266,8 +272,9 @@ func (c *Client) Close() error {
|
|||||||
func (c *Client) Use(hooks ...Hook) {
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
for _, n := range []interface{ Use(...Hook) }{
|
for _, n := range []interface{ Use(...Hook) }{
|
||||||
c.APIKey, c.Account, c.AccountGroup, c.Group, c.PromoCode, c.PromoCodeUsage,
|
c.APIKey, c.Account, c.AccountGroup, c.Group, c.PromoCode, c.PromoCodeUsage,
|
||||||
c.Proxy, c.RedeemCode, c.Setting, c.UsageLog, c.User, c.UserAllowedGroup,
|
c.Proxy, c.RedeemCode, c.Setting, c.UsageCleanupTask, c.UsageLog, c.User,
|
||||||
c.UserAttributeDefinition, c.UserAttributeValue, c.UserSubscription,
|
c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
|
||||||
|
c.UserSubscription,
|
||||||
} {
|
} {
|
||||||
n.Use(hooks...)
|
n.Use(hooks...)
|
||||||
}
|
}
|
||||||
@@ -278,8 +285,9 @@ func (c *Client) Use(hooks ...Hook) {
|
|||||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||||
c.APIKey, c.Account, c.AccountGroup, c.Group, c.PromoCode, c.PromoCodeUsage,
|
c.APIKey, c.Account, c.AccountGroup, c.Group, c.PromoCode, c.PromoCodeUsage,
|
||||||
c.Proxy, c.RedeemCode, c.Setting, c.UsageLog, c.User, c.UserAllowedGroup,
|
c.Proxy, c.RedeemCode, c.Setting, c.UsageCleanupTask, c.UsageLog, c.User,
|
||||||
c.UserAttributeDefinition, c.UserAttributeValue, c.UserSubscription,
|
c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
|
||||||
|
c.UserSubscription,
|
||||||
} {
|
} {
|
||||||
n.Intercept(interceptors...)
|
n.Intercept(interceptors...)
|
||||||
}
|
}
|
||||||
@@ -306,6 +314,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|||||||
return c.RedeemCode.mutate(ctx, m)
|
return c.RedeemCode.mutate(ctx, m)
|
||||||
case *SettingMutation:
|
case *SettingMutation:
|
||||||
return c.Setting.mutate(ctx, m)
|
return c.Setting.mutate(ctx, m)
|
||||||
|
case *UsageCleanupTaskMutation:
|
||||||
|
return c.UsageCleanupTask.mutate(ctx, m)
|
||||||
case *UsageLogMutation:
|
case *UsageLogMutation:
|
||||||
return c.UsageLog.mutate(ctx, m)
|
return c.UsageLog.mutate(ctx, m)
|
||||||
case *UserMutation:
|
case *UserMutation:
|
||||||
@@ -1847,6 +1857,139 @@ func (c *SettingClient) mutate(ctx context.Context, m *SettingMutation) (Value,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UsageCleanupTaskClient is a client for the UsageCleanupTask schema.
|
||||||
|
type UsageCleanupTaskClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUsageCleanupTaskClient returns a client for the UsageCleanupTask from the given config.
|
||||||
|
func NewUsageCleanupTaskClient(c config) *UsageCleanupTaskClient {
|
||||||
|
return &UsageCleanupTaskClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `usagecleanuptask.Hooks(f(g(h())))`.
|
||||||
|
func (c *UsageCleanupTaskClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.UsageCleanupTask = append(c.hooks.UsageCleanupTask, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `usagecleanuptask.Intercept(f(g(h())))`.
|
||||||
|
func (c *UsageCleanupTaskClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.UsageCleanupTask = append(c.inters.UsageCleanupTask, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a UsageCleanupTask entity.
|
||||||
|
func (c *UsageCleanupTaskClient) Create() *UsageCleanupTaskCreate {
|
||||||
|
mutation := newUsageCleanupTaskMutation(c.config, OpCreate)
|
||||||
|
return &UsageCleanupTaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of UsageCleanupTask entities.
|
||||||
|
func (c *UsageCleanupTaskClient) CreateBulk(builders ...*UsageCleanupTaskCreate) *UsageCleanupTaskCreateBulk {
|
||||||
|
return &UsageCleanupTaskCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *UsageCleanupTaskClient) MapCreateBulk(slice any, setFunc func(*UsageCleanupTaskCreate, int)) *UsageCleanupTaskCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &UsageCleanupTaskCreateBulk{err: fmt.Errorf("calling to UsageCleanupTaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*UsageCleanupTaskCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &UsageCleanupTaskCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for UsageCleanupTask.
|
||||||
|
func (c *UsageCleanupTaskClient) Update() *UsageCleanupTaskUpdate {
|
||||||
|
mutation := newUsageCleanupTaskMutation(c.config, OpUpdate)
|
||||||
|
return &UsageCleanupTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *UsageCleanupTaskClient) UpdateOne(_m *UsageCleanupTask) *UsageCleanupTaskUpdateOne {
|
||||||
|
mutation := newUsageCleanupTaskMutation(c.config, OpUpdateOne, withUsageCleanupTask(_m))
|
||||||
|
return &UsageCleanupTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *UsageCleanupTaskClient) UpdateOneID(id int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
mutation := newUsageCleanupTaskMutation(c.config, OpUpdateOne, withUsageCleanupTaskID(id))
|
||||||
|
return &UsageCleanupTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for UsageCleanupTask.
|
||||||
|
func (c *UsageCleanupTaskClient) Delete() *UsageCleanupTaskDelete {
|
||||||
|
mutation := newUsageCleanupTaskMutation(c.config, OpDelete)
|
||||||
|
return &UsageCleanupTaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *UsageCleanupTaskClient) DeleteOne(_m *UsageCleanupTask) *UsageCleanupTaskDeleteOne {
|
||||||
|
return c.DeleteOneID(_m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *UsageCleanupTaskClient) DeleteOneID(id int64) *UsageCleanupTaskDeleteOne {
|
||||||
|
builder := c.Delete().Where(usagecleanuptask.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &UsageCleanupTaskDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for UsageCleanupTask.
|
||||||
|
func (c *UsageCleanupTaskClient) Query() *UsageCleanupTaskQuery {
|
||||||
|
return &UsageCleanupTaskQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeUsageCleanupTask},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a UsageCleanupTask entity by its id.
|
||||||
|
func (c *UsageCleanupTaskClient) Get(ctx context.Context, id int64) (*UsageCleanupTask, error) {
|
||||||
|
return c.Query().Where(usagecleanuptask.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *UsageCleanupTaskClient) GetX(ctx context.Context, id int64) *UsageCleanupTask {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *UsageCleanupTaskClient) Hooks() []Hook {
|
||||||
|
return c.hooks.UsageCleanupTask
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *UsageCleanupTaskClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.UsageCleanupTask
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *UsageCleanupTaskClient) mutate(ctx context.Context, m *UsageCleanupTaskMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&UsageCleanupTaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&UsageCleanupTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&UsageCleanupTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&UsageCleanupTaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown UsageCleanupTask mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UsageLogClient is a client for the UsageLog schema.
|
// UsageLogClient is a client for the UsageLog schema.
|
||||||
type UsageLogClient struct {
|
type UsageLogClient struct {
|
||||||
config
|
config
|
||||||
@@ -2974,13 +3117,13 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
|
|||||||
type (
|
type (
|
||||||
hooks struct {
|
hooks struct {
|
||||||
APIKey, Account, AccountGroup, Group, PromoCode, PromoCodeUsage, Proxy,
|
APIKey, Account, AccountGroup, Group, PromoCode, PromoCodeUsage, Proxy,
|
||||||
RedeemCode, Setting, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
|
RedeemCode, Setting, UsageCleanupTask, UsageLog, User, UserAllowedGroup,
|
||||||
UserAttributeValue, UserSubscription []ent.Hook
|
UserAttributeDefinition, UserAttributeValue, UserSubscription []ent.Hook
|
||||||
}
|
}
|
||||||
inters struct {
|
inters struct {
|
||||||
APIKey, Account, AccountGroup, Group, PromoCode, PromoCodeUsage, Proxy,
|
APIKey, Account, AccountGroup, Group, PromoCode, PromoCodeUsage, Proxy,
|
||||||
RedeemCode, Setting, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
|
RedeemCode, Setting, UsageCleanupTask, UsageLog, User, UserAllowedGroup,
|
||||||
UserAttributeValue, UserSubscription []ent.Interceptor
|
UserAttributeDefinition, UserAttributeValue, UserSubscription []ent.Interceptor
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/setting"
|
"github.com/Wei-Shaw/sub2api/ent/setting"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/user"
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
||||||
@@ -96,6 +97,7 @@ func checkColumn(t, c string) error {
|
|||||||
proxy.Table: proxy.ValidColumn,
|
proxy.Table: proxy.ValidColumn,
|
||||||
redeemcode.Table: redeemcode.ValidColumn,
|
redeemcode.Table: redeemcode.ValidColumn,
|
||||||
setting.Table: setting.ValidColumn,
|
setting.Table: setting.ValidColumn,
|
||||||
|
usagecleanuptask.Table: usagecleanuptask.ValidColumn,
|
||||||
usagelog.Table: usagelog.ValidColumn,
|
usagelog.Table: usagelog.ValidColumn,
|
||||||
user.Table: user.ValidColumn,
|
user.Table: user.ValidColumn,
|
||||||
userallowedgroup.Table: userallowedgroup.ValidColumn,
|
userallowedgroup.Table: userallowedgroup.ValidColumn,
|
||||||
|
|||||||
@@ -117,6 +117,18 @@ func (f SettingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
|
|||||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SettingMutation", m)
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SettingMutation", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The UsageCleanupTaskFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as UsageCleanupTask mutator.
|
||||||
|
type UsageCleanupTaskFunc func(context.Context, *ent.UsageCleanupTaskMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f UsageCleanupTaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.UsageCleanupTaskMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageCleanupTaskMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
// The UsageLogFunc type is an adapter to allow the use of ordinary
|
// The UsageLogFunc type is an adapter to allow the use of ordinary
|
||||||
// function as UsageLog mutator.
|
// function as UsageLog mutator.
|
||||||
type UsageLogFunc func(context.Context, *ent.UsageLogMutation) (ent.Value, error)
|
type UsageLogFunc func(context.Context, *ent.UsageLogMutation) (ent.Value, error)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
"github.com/Wei-Shaw/sub2api/ent/proxy"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/setting"
|
"github.com/Wei-Shaw/sub2api/ent/setting"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/user"
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
||||||
@@ -325,6 +326,33 @@ func (f TraverseSetting) Traverse(ctx context.Context, q ent.Query) error {
|
|||||||
return fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q)
|
return fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The UsageCleanupTaskFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
|
type UsageCleanupTaskFunc func(context.Context, *ent.UsageCleanupTaskQuery) (ent.Value, error)
|
||||||
|
|
||||||
|
// Query calls f(ctx, q).
|
||||||
|
func (f UsageCleanupTaskFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||||
|
if q, ok := q.(*ent.UsageCleanupTaskQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UsageCleanupTaskQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The TraverseUsageCleanupTask type is an adapter to allow the use of ordinary function as Traverser.
|
||||||
|
type TraverseUsageCleanupTask func(context.Context, *ent.UsageCleanupTaskQuery) error
|
||||||
|
|
||||||
|
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||||
|
func (f TraverseUsageCleanupTask) Intercept(next ent.Querier) ent.Querier {
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
// Traverse calls f(ctx, q).
|
||||||
|
func (f TraverseUsageCleanupTask) Traverse(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.UsageCleanupTaskQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected query type %T. expect *ent.UsageCleanupTaskQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
// The UsageLogFunc type is an adapter to allow the use of ordinary function as a Querier.
|
// The UsageLogFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||||
type UsageLogFunc func(context.Context, *ent.UsageLogQuery) (ent.Value, error)
|
type UsageLogFunc func(context.Context, *ent.UsageLogQuery) (ent.Value, error)
|
||||||
|
|
||||||
@@ -508,6 +536,8 @@ func NewQuery(q ent.Query) (Query, error) {
|
|||||||
return &query[*ent.RedeemCodeQuery, predicate.RedeemCode, redeemcode.OrderOption]{typ: ent.TypeRedeemCode, tq: q}, nil
|
return &query[*ent.RedeemCodeQuery, predicate.RedeemCode, redeemcode.OrderOption]{typ: ent.TypeRedeemCode, tq: q}, nil
|
||||||
case *ent.SettingQuery:
|
case *ent.SettingQuery:
|
||||||
return &query[*ent.SettingQuery, predicate.Setting, setting.OrderOption]{typ: ent.TypeSetting, tq: q}, nil
|
return &query[*ent.SettingQuery, predicate.Setting, setting.OrderOption]{typ: ent.TypeSetting, tq: q}, nil
|
||||||
|
case *ent.UsageCleanupTaskQuery:
|
||||||
|
return &query[*ent.UsageCleanupTaskQuery, predicate.UsageCleanupTask, usagecleanuptask.OrderOption]{typ: ent.TypeUsageCleanupTask, tq: q}, nil
|
||||||
case *ent.UsageLogQuery:
|
case *ent.UsageLogQuery:
|
||||||
return &query[*ent.UsageLogQuery, predicate.UsageLog, usagelog.OrderOption]{typ: ent.TypeUsageLog, tq: q}, nil
|
return &query[*ent.UsageLogQuery, predicate.UsageLog, usagelog.OrderOption]{typ: ent.TypeUsageLog, tq: q}, nil
|
||||||
case *ent.UserQuery:
|
case *ent.UserQuery:
|
||||||
|
|||||||
@@ -434,6 +434,44 @@ var (
|
|||||||
Columns: SettingsColumns,
|
Columns: SettingsColumns,
|
||||||
PrimaryKey: []*schema.Column{SettingsColumns[0]},
|
PrimaryKey: []*schema.Column{SettingsColumns[0]},
|
||||||
}
|
}
|
||||||
|
// UsageCleanupTasksColumns holds the columns for the "usage_cleanup_tasks" table.
|
||||||
|
UsageCleanupTasksColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
|
||||||
|
{Name: "status", Type: field.TypeString, Size: 20},
|
||||||
|
{Name: "filters", Type: field.TypeJSON},
|
||||||
|
{Name: "created_by", Type: field.TypeInt64},
|
||||||
|
{Name: "deleted_rows", Type: field.TypeInt64, Default: 0},
|
||||||
|
{Name: "error_message", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "canceled_by", Type: field.TypeInt64, Nullable: true},
|
||||||
|
{Name: "canceled_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "started_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "finished_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
}
|
||||||
|
// UsageCleanupTasksTable holds the schema information for the "usage_cleanup_tasks" table.
|
||||||
|
UsageCleanupTasksTable = &schema.Table{
|
||||||
|
Name: "usage_cleanup_tasks",
|
||||||
|
Columns: UsageCleanupTasksColumns,
|
||||||
|
PrimaryKey: []*schema.Column{UsageCleanupTasksColumns[0]},
|
||||||
|
Indexes: []*schema.Index{
|
||||||
|
{
|
||||||
|
Name: "usagecleanuptask_status_created_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{UsageCleanupTasksColumns[3], UsageCleanupTasksColumns[1]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "usagecleanuptask_created_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{UsageCleanupTasksColumns[1]},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "usagecleanuptask_canceled_at",
|
||||||
|
Unique: false,
|
||||||
|
Columns: []*schema.Column{UsageCleanupTasksColumns[9]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
// UsageLogsColumns holds the columns for the "usage_logs" table.
|
// UsageLogsColumns holds the columns for the "usage_logs" table.
|
||||||
UsageLogsColumns = []*schema.Column{
|
UsageLogsColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
@@ -805,6 +843,7 @@ var (
|
|||||||
ProxiesTable,
|
ProxiesTable,
|
||||||
RedeemCodesTable,
|
RedeemCodesTable,
|
||||||
SettingsTable,
|
SettingsTable,
|
||||||
|
UsageCleanupTasksTable,
|
||||||
UsageLogsTable,
|
UsageLogsTable,
|
||||||
UsersTable,
|
UsersTable,
|
||||||
UserAllowedGroupsTable,
|
UserAllowedGroupsTable,
|
||||||
@@ -851,6 +890,9 @@ func init() {
|
|||||||
SettingsTable.Annotation = &entsql.Annotation{
|
SettingsTable.Annotation = &entsql.Annotation{
|
||||||
Table: "settings",
|
Table: "settings",
|
||||||
}
|
}
|
||||||
|
UsageCleanupTasksTable.Annotation = &entsql.Annotation{
|
||||||
|
Table: "usage_cleanup_tasks",
|
||||||
|
}
|
||||||
UsageLogsTable.ForeignKeys[0].RefTable = APIKeysTable
|
UsageLogsTable.ForeignKeys[0].RefTable = APIKeysTable
|
||||||
UsageLogsTable.ForeignKeys[1].RefTable = AccountsTable
|
UsageLogsTable.ForeignKeys[1].RefTable = AccountsTable
|
||||||
UsageLogsTable.ForeignKeys[2].RefTable = GroupsTable
|
UsageLogsTable.ForeignKeys[2].RefTable = GroupsTable
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,9 @@ type RedeemCode func(*sql.Selector)
|
|||||||
// Setting is the predicate function for setting builders.
|
// Setting is the predicate function for setting builders.
|
||||||
type Setting func(*sql.Selector)
|
type Setting func(*sql.Selector)
|
||||||
|
|
||||||
|
// UsageCleanupTask is the predicate function for usagecleanuptask builders.
|
||||||
|
type UsageCleanupTask func(*sql.Selector)
|
||||||
|
|
||||||
// UsageLog is the predicate function for usagelog builders.
|
// UsageLog is the predicate function for usagelog builders.
|
||||||
type UsageLog func(*sql.Selector)
|
type UsageLog func(*sql.Selector)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/schema"
|
"github.com/Wei-Shaw/sub2api/ent/schema"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/setting"
|
"github.com/Wei-Shaw/sub2api/ent/setting"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/user"
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||||
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
|
||||||
@@ -495,6 +496,43 @@ func init() {
|
|||||||
setting.DefaultUpdatedAt = settingDescUpdatedAt.Default.(func() time.Time)
|
setting.DefaultUpdatedAt = settingDescUpdatedAt.Default.(func() time.Time)
|
||||||
// setting.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
// setting.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
setting.UpdateDefaultUpdatedAt = settingDescUpdatedAt.UpdateDefault.(func() time.Time)
|
setting.UpdateDefaultUpdatedAt = settingDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
usagecleanuptaskMixin := schema.UsageCleanupTask{}.Mixin()
|
||||||
|
usagecleanuptaskMixinFields0 := usagecleanuptaskMixin[0].Fields()
|
||||||
|
_ = usagecleanuptaskMixinFields0
|
||||||
|
usagecleanuptaskFields := schema.UsageCleanupTask{}.Fields()
|
||||||
|
_ = usagecleanuptaskFields
|
||||||
|
// usagecleanuptaskDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
usagecleanuptaskDescCreatedAt := usagecleanuptaskMixinFields0[0].Descriptor()
|
||||||
|
// usagecleanuptask.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
usagecleanuptask.DefaultCreatedAt = usagecleanuptaskDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// usagecleanuptaskDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
usagecleanuptaskDescUpdatedAt := usagecleanuptaskMixinFields0[1].Descriptor()
|
||||||
|
// usagecleanuptask.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
usagecleanuptask.DefaultUpdatedAt = usagecleanuptaskDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// usagecleanuptask.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
usagecleanuptask.UpdateDefaultUpdatedAt = usagecleanuptaskDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// usagecleanuptaskDescStatus is the schema descriptor for status field.
|
||||||
|
usagecleanuptaskDescStatus := usagecleanuptaskFields[0].Descriptor()
|
||||||
|
// usagecleanuptask.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
|
usagecleanuptask.StatusValidator = func() func(string) error {
|
||||||
|
validators := usagecleanuptaskDescStatus.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(status string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(status); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// usagecleanuptaskDescDeletedRows is the schema descriptor for deleted_rows field.
|
||||||
|
usagecleanuptaskDescDeletedRows := usagecleanuptaskFields[3].Descriptor()
|
||||||
|
// usagecleanuptask.DefaultDeletedRows holds the default value on creation for the deleted_rows field.
|
||||||
|
usagecleanuptask.DefaultDeletedRows = usagecleanuptaskDescDeletedRows.Default.(int64)
|
||||||
usagelogFields := schema.UsageLog{}.Fields()
|
usagelogFields := schema.UsageLog{}.Fields()
|
||||||
_ = usagelogFields
|
_ = usagelogFields
|
||||||
// usagelogDescRequestID is the schema descriptor for request_id field.
|
// usagelogDescRequestID is the schema descriptor for request_id field.
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"entgo.io/ent/dialect/sql"
|
"entgo.io/ent/dialect/sql"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"entgo.io/ent/schema/mixin"
|
"entgo.io/ent/schema/mixin"
|
||||||
dbent "github.com/Wei-Shaw/sub2api/ent"
|
|
||||||
"github.com/Wei-Shaw/sub2api/ent/intercept"
|
"github.com/Wei-Shaw/sub2api/ent/intercept"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -113,7 +112,9 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
|
|||||||
SetOp(ent.Op)
|
SetOp(ent.Op)
|
||||||
SetDeletedAt(time.Time)
|
SetDeletedAt(time.Time)
|
||||||
WhereP(...func(*sql.Selector))
|
WhereP(...func(*sql.Selector))
|
||||||
Client() *dbent.Client
|
Client() interface {
|
||||||
|
Mutate(context.Context, ent.Mutation) (ent.Value, error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
|||||||
75
backend/ent/schema/usage_cleanup_task.go
Normal file
75
backend/ent/schema/usage_cleanup_task.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
|
"entgo.io/ent/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UsageCleanupTask 定义使用记录清理任务的 schema。
|
||||||
|
type UsageCleanupTask struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UsageCleanupTask) Annotations() []schema.Annotation {
|
||||||
|
return []schema.Annotation{
|
||||||
|
entsql.Annotation{Table: "usage_cleanup_tasks"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UsageCleanupTask) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.TimeMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UsageCleanupTask) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.String("status").
|
||||||
|
MaxLen(20).
|
||||||
|
Validate(validateUsageCleanupStatus),
|
||||||
|
field.JSON("filters", json.RawMessage{}),
|
||||||
|
field.Int64("created_by"),
|
||||||
|
field.Int64("deleted_rows").
|
||||||
|
Default(0),
|
||||||
|
field.String("error_message").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
field.Int64("canceled_by").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
field.Time("canceled_at").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
field.Time("started_at").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
field.Time("finished_at").
|
||||||
|
Optional().
|
||||||
|
Nillable(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UsageCleanupTask) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("status", "created_at"),
|
||||||
|
index.Fields("created_at"),
|
||||||
|
index.Fields("canceled_at"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateUsageCleanupStatus(status string) error {
|
||||||
|
switch status {
|
||||||
|
case "pending", "running", "succeeded", "failed", "canceled":
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid usage cleanup status: %s", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,8 @@ type Tx struct {
|
|||||||
RedeemCode *RedeemCodeClient
|
RedeemCode *RedeemCodeClient
|
||||||
// Setting is the client for interacting with the Setting builders.
|
// Setting is the client for interacting with the Setting builders.
|
||||||
Setting *SettingClient
|
Setting *SettingClient
|
||||||
|
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
|
||||||
|
UsageCleanupTask *UsageCleanupTaskClient
|
||||||
// UsageLog is the client for interacting with the UsageLog builders.
|
// UsageLog is the client for interacting with the UsageLog builders.
|
||||||
UsageLog *UsageLogClient
|
UsageLog *UsageLogClient
|
||||||
// User is the client for interacting with the User builders.
|
// User is the client for interacting with the User builders.
|
||||||
@@ -184,6 +186,7 @@ func (tx *Tx) init() {
|
|||||||
tx.Proxy = NewProxyClient(tx.config)
|
tx.Proxy = NewProxyClient(tx.config)
|
||||||
tx.RedeemCode = NewRedeemCodeClient(tx.config)
|
tx.RedeemCode = NewRedeemCodeClient(tx.config)
|
||||||
tx.Setting = NewSettingClient(tx.config)
|
tx.Setting = NewSettingClient(tx.config)
|
||||||
|
tx.UsageCleanupTask = NewUsageCleanupTaskClient(tx.config)
|
||||||
tx.UsageLog = NewUsageLogClient(tx.config)
|
tx.UsageLog = NewUsageLogClient(tx.config)
|
||||||
tx.User = NewUserClient(tx.config)
|
tx.User = NewUserClient(tx.config)
|
||||||
tx.UserAllowedGroup = NewUserAllowedGroupClient(tx.config)
|
tx.UserAllowedGroup = NewUserAllowedGroupClient(tx.config)
|
||||||
|
|||||||
236
backend/ent/usagecleanuptask.go
Normal file
236
backend/ent/usagecleanuptask.go
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UsageCleanupTask is the model entity for the UsageCleanupTask schema.
|
||||||
|
type UsageCleanupTask struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
// Status holds the value of the "status" field.
|
||||||
|
Status string `json:"status,omitempty"`
|
||||||
|
// Filters holds the value of the "filters" field.
|
||||||
|
Filters json.RawMessage `json:"filters,omitempty"`
|
||||||
|
// CreatedBy holds the value of the "created_by" field.
|
||||||
|
CreatedBy int64 `json:"created_by,omitempty"`
|
||||||
|
// DeletedRows holds the value of the "deleted_rows" field.
|
||||||
|
DeletedRows int64 `json:"deleted_rows,omitempty"`
|
||||||
|
// ErrorMessage holds the value of the "error_message" field.
|
||||||
|
ErrorMessage *string `json:"error_message,omitempty"`
|
||||||
|
// CanceledBy holds the value of the "canceled_by" field.
|
||||||
|
CanceledBy *int64 `json:"canceled_by,omitempty"`
|
||||||
|
// CanceledAt holds the value of the "canceled_at" field.
|
||||||
|
CanceledAt *time.Time `json:"canceled_at,omitempty"`
|
||||||
|
// StartedAt holds the value of the "started_at" field.
|
||||||
|
StartedAt *time.Time `json:"started_at,omitempty"`
|
||||||
|
// FinishedAt holds the value of the "finished_at" field.
|
||||||
|
FinishedAt *time.Time `json:"finished_at,omitempty"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*UsageCleanupTask) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case usagecleanuptask.FieldFilters:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case usagecleanuptask.FieldID, usagecleanuptask.FieldCreatedBy, usagecleanuptask.FieldDeletedRows, usagecleanuptask.FieldCanceledBy:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case usagecleanuptask.FieldStatus, usagecleanuptask.FieldErrorMessage:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case usagecleanuptask.FieldCreatedAt, usagecleanuptask.FieldUpdatedAt, usagecleanuptask.FieldCanceledAt, usagecleanuptask.FieldStartedAt, usagecleanuptask.FieldFinishedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the UsageCleanupTask fields.
|
||||||
|
func (_m *UsageCleanupTask) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case usagecleanuptask.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
_m.ID = int64(value.Int64)
|
||||||
|
case usagecleanuptask.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldStatus:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.Status = value.String
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldFilters:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field filters", values[i])
|
||||||
|
} else if value != nil && len(*value) > 0 {
|
||||||
|
if err := json.Unmarshal(*value, &_m.Filters); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal field filters: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldCreatedBy:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_by", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CreatedBy = value.Int64
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldDeletedRows:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field deleted_rows", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.DeletedRows = value.Int64
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldErrorMessage:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field error_message", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.ErrorMessage = new(string)
|
||||||
|
*_m.ErrorMessage = value.String
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldCanceledBy:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field canceled_by", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CanceledBy = new(int64)
|
||||||
|
*_m.CanceledBy = value.Int64
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldCanceledAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field canceled_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.CanceledAt = new(time.Time)
|
||||||
|
*_m.CanceledAt = value.Time
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldStartedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field started_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.StartedAt = new(time.Time)
|
||||||
|
*_m.StartedAt = value.Time
|
||||||
|
}
|
||||||
|
case usagecleanuptask.FieldFinishedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field finished_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
_m.FinishedAt = new(time.Time)
|
||||||
|
*_m.FinishedAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_m.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the UsageCleanupTask.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *UsageCleanupTask) Value(name string) (ent.Value, error) {
|
||||||
|
return _m.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this UsageCleanupTask.
|
||||||
|
// Note that you need to call UsageCleanupTask.Unwrap() before calling this method if this UsageCleanupTask
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *UsageCleanupTask) Update() *UsageCleanupTaskUpdateOne {
|
||||||
|
return NewUsageCleanupTaskClient(_m.config).UpdateOne(_m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the UsageCleanupTask entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (_m *UsageCleanupTask) Unwrap() *UsageCleanupTask {
|
||||||
|
_tx, ok := _m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: UsageCleanupTask is not a transactional entity")
|
||||||
|
}
|
||||||
|
_m.config.driver = _tx.drv
|
||||||
|
return _m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *UsageCleanupTask) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("UsageCleanupTask(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("status=")
|
||||||
|
builder.WriteString(_m.Status)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("filters=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.Filters))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("created_by=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.CreatedBy))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("deleted_rows=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.DeletedRows))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.ErrorMessage; v != nil {
|
||||||
|
builder.WriteString("error_message=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.CanceledBy; v != nil {
|
||||||
|
builder.WriteString("canceled_by=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.CanceledAt; v != nil {
|
||||||
|
builder.WriteString("canceled_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.StartedAt; v != nil {
|
||||||
|
builder.WriteString("started_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := _m.FinishedAt; v != nil {
|
||||||
|
builder.WriteString("finished_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsageCleanupTasks is a parsable slice of UsageCleanupTask.
|
||||||
|
type UsageCleanupTasks []*UsageCleanupTask
|
||||||
137
backend/ent/usagecleanuptask/usagecleanuptask.go
Normal file
137
backend/ent/usagecleanuptask/usagecleanuptask.go
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package usagecleanuptask
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the usagecleanuptask type in the database.
|
||||||
|
Label = "usage_cleanup_task"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldStatus holds the string denoting the status field in the database.
|
||||||
|
FieldStatus = "status"
|
||||||
|
// FieldFilters holds the string denoting the filters field in the database.
|
||||||
|
FieldFilters = "filters"
|
||||||
|
// FieldCreatedBy holds the string denoting the created_by field in the database.
|
||||||
|
FieldCreatedBy = "created_by"
|
||||||
|
// FieldDeletedRows holds the string denoting the deleted_rows field in the database.
|
||||||
|
FieldDeletedRows = "deleted_rows"
|
||||||
|
// FieldErrorMessage holds the string denoting the error_message field in the database.
|
||||||
|
FieldErrorMessage = "error_message"
|
||||||
|
// FieldCanceledBy holds the string denoting the canceled_by field in the database.
|
||||||
|
FieldCanceledBy = "canceled_by"
|
||||||
|
// FieldCanceledAt holds the string denoting the canceled_at field in the database.
|
||||||
|
FieldCanceledAt = "canceled_at"
|
||||||
|
// FieldStartedAt holds the string denoting the started_at field in the database.
|
||||||
|
FieldStartedAt = "started_at"
|
||||||
|
// FieldFinishedAt holds the string denoting the finished_at field in the database.
|
||||||
|
FieldFinishedAt = "finished_at"
|
||||||
|
// Table holds the table name of the usagecleanuptask in the database.
|
||||||
|
Table = "usage_cleanup_tasks"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for usagecleanuptask fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldStatus,
|
||||||
|
FieldFilters,
|
||||||
|
FieldCreatedBy,
|
||||||
|
FieldDeletedRows,
|
||||||
|
FieldErrorMessage,
|
||||||
|
FieldCanceledBy,
|
||||||
|
FieldCanceledAt,
|
||||||
|
FieldStartedAt,
|
||||||
|
FieldFinishedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
|
StatusValidator func(string) error
|
||||||
|
// DefaultDeletedRows holds the default value on creation for the "deleted_rows" field.
|
||||||
|
DefaultDeletedRows int64
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the UsageCleanupTask queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByStatus orders the results by the status field.
|
||||||
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedBy orders the results by the created_by field.
|
||||||
|
func ByCreatedBy(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedBy, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDeletedRows orders the results by the deleted_rows field.
|
||||||
|
func ByDeletedRows(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDeletedRows, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByErrorMessage orders the results by the error_message field.
|
||||||
|
func ByErrorMessage(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldErrorMessage, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCanceledBy orders the results by the canceled_by field.
|
||||||
|
func ByCanceledBy(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCanceledBy, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCanceledAt orders the results by the canceled_at field.
|
||||||
|
func ByCanceledAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCanceledAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByStartedAt orders the results by the started_at field.
|
||||||
|
func ByStartedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldStartedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByFinishedAt orders the results by the finished_at field.
|
||||||
|
func ByFinishedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldFinishedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
620
backend/ent/usagecleanuptask/where.go
Normal file
620
backend/ent/usagecleanuptask/where.go
Normal file
@@ -0,0 +1,620 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package usagecleanuptask
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||||
|
func Status(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedBy applies equality check predicate on the "created_by" field. It's identical to CreatedByEQ.
|
||||||
|
func CreatedBy(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRows applies equality check predicate on the "deleted_rows" field. It's identical to DeletedRowsEQ.
|
||||||
|
func DeletedRows(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ.
|
||||||
|
func ErrorMessage(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledBy applies equality check predicate on the "canceled_by" field. It's identical to CanceledByEQ.
|
||||||
|
func CanceledBy(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAt applies equality check predicate on the "canceled_at" field. It's identical to CanceledAtEQ.
|
||||||
|
func CanceledAt(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAt applies equality check predicate on the "started_at" field. It's identical to StartedAtEQ.
|
||||||
|
func StartedAt(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAt applies equality check predicate on the "finished_at" field. It's identical to FinishedAtEQ.
|
||||||
|
func FinishedAt(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEQ applies the EQ predicate on the "status" field.
|
||||||
|
func StatusEQ(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||||
|
func StatusNEQ(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusIn applies the In predicate on the "status" field.
|
||||||
|
func StatusIn(vs ...string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldStatus, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||||
|
func StatusNotIn(vs ...string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldStatus, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusGT applies the GT predicate on the "status" field.
|
||||||
|
func StatusGT(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusGTE applies the GTE predicate on the "status" field.
|
||||||
|
func StatusGTE(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusLT applies the LT predicate on the "status" field.
|
||||||
|
func StatusLT(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusLTE applies the LTE predicate on the "status" field.
|
||||||
|
func StatusLTE(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusContains applies the Contains predicate on the "status" field.
|
||||||
|
func StatusContains(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldContains(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
|
||||||
|
func StatusHasPrefix(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldHasPrefix(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
|
||||||
|
func StatusHasSuffix(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldHasSuffix(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusEqualFold applies the EqualFold predicate on the "status" field.
|
||||||
|
func StatusEqualFold(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEqualFold(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
|
||||||
|
func StatusContainsFold(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldContainsFold(FieldStatus, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByEQ applies the EQ predicate on the "created_by" field.
|
||||||
|
func CreatedByEQ(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByNEQ applies the NEQ predicate on the "created_by" field.
|
||||||
|
func CreatedByNEQ(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByIn applies the In predicate on the "created_by" field.
|
||||||
|
func CreatedByIn(vs ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldCreatedBy, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByNotIn applies the NotIn predicate on the "created_by" field.
|
||||||
|
func CreatedByNotIn(vs ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldCreatedBy, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByGT applies the GT predicate on the "created_by" field.
|
||||||
|
func CreatedByGT(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByGTE applies the GTE predicate on the "created_by" field.
|
||||||
|
func CreatedByGTE(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByLT applies the LT predicate on the "created_by" field.
|
||||||
|
func CreatedByLT(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedByLTE applies the LTE predicate on the "created_by" field.
|
||||||
|
func CreatedByLTE(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldCreatedBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsEQ applies the EQ predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsEQ(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsNEQ applies the NEQ predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsNEQ(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsIn applies the In predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsIn(vs ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldDeletedRows, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsNotIn applies the NotIn predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsNotIn(vs ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldDeletedRows, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsGT applies the GT predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsGT(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsGTE applies the GTE predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsGTE(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsLT applies the LT predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsLT(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedRowsLTE applies the LTE predicate on the "deleted_rows" field.
|
||||||
|
func DeletedRowsLTE(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldDeletedRows, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageEQ applies the EQ predicate on the "error_message" field.
|
||||||
|
func ErrorMessageEQ(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field.
|
||||||
|
func ErrorMessageNEQ(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageIn applies the In predicate on the "error_message" field.
|
||||||
|
func ErrorMessageIn(vs ...string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldErrorMessage, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field.
|
||||||
|
func ErrorMessageNotIn(vs ...string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldErrorMessage, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageGT applies the GT predicate on the "error_message" field.
|
||||||
|
func ErrorMessageGT(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageGTE applies the GTE predicate on the "error_message" field.
|
||||||
|
func ErrorMessageGTE(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageLT applies the LT predicate on the "error_message" field.
|
||||||
|
func ErrorMessageLT(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageLTE applies the LTE predicate on the "error_message" field.
|
||||||
|
func ErrorMessageLTE(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageContains applies the Contains predicate on the "error_message" field.
|
||||||
|
func ErrorMessageContains(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldContains(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field.
|
||||||
|
func ErrorMessageHasPrefix(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldHasPrefix(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field.
|
||||||
|
func ErrorMessageHasSuffix(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldHasSuffix(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field.
|
||||||
|
func ErrorMessageIsNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIsNull(FieldErrorMessage))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field.
|
||||||
|
func ErrorMessageNotNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotNull(FieldErrorMessage))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field.
|
||||||
|
func ErrorMessageEqualFold(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEqualFold(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field.
|
||||||
|
func ErrorMessageContainsFold(v string) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldContainsFold(FieldErrorMessage, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByEQ applies the EQ predicate on the "canceled_by" field.
|
||||||
|
func CanceledByEQ(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByNEQ applies the NEQ predicate on the "canceled_by" field.
|
||||||
|
func CanceledByNEQ(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByIn applies the In predicate on the "canceled_by" field.
|
||||||
|
func CanceledByIn(vs ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldCanceledBy, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByNotIn applies the NotIn predicate on the "canceled_by" field.
|
||||||
|
func CanceledByNotIn(vs ...int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldCanceledBy, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByGT applies the GT predicate on the "canceled_by" field.
|
||||||
|
func CanceledByGT(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByGTE applies the GTE predicate on the "canceled_by" field.
|
||||||
|
func CanceledByGTE(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByLT applies the LT predicate on the "canceled_by" field.
|
||||||
|
func CanceledByLT(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByLTE applies the LTE predicate on the "canceled_by" field.
|
||||||
|
func CanceledByLTE(v int64) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldCanceledBy, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByIsNil applies the IsNil predicate on the "canceled_by" field.
|
||||||
|
func CanceledByIsNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIsNull(FieldCanceledBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledByNotNil applies the NotNil predicate on the "canceled_by" field.
|
||||||
|
func CanceledByNotNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotNull(FieldCanceledBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtEQ applies the EQ predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtNEQ applies the NEQ predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtNEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtIn applies the In predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldCanceledAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtNotIn applies the NotIn predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtNotIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldCanceledAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtGT applies the GT predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtGT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtGTE applies the GTE predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtGTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtLT applies the LT predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtLT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtLTE applies the LTE predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtLTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldCanceledAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtIsNil applies the IsNil predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtIsNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIsNull(FieldCanceledAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanceledAtNotNil applies the NotNil predicate on the "canceled_at" field.
|
||||||
|
func CanceledAtNotNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotNull(FieldCanceledAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtEQ applies the EQ predicate on the "started_at" field.
|
||||||
|
func StartedAtEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtNEQ applies the NEQ predicate on the "started_at" field.
|
||||||
|
func StartedAtNEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtIn applies the In predicate on the "started_at" field.
|
||||||
|
func StartedAtIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldStartedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtNotIn applies the NotIn predicate on the "started_at" field.
|
||||||
|
func StartedAtNotIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldStartedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtGT applies the GT predicate on the "started_at" field.
|
||||||
|
func StartedAtGT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtGTE applies the GTE predicate on the "started_at" field.
|
||||||
|
func StartedAtGTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtLT applies the LT predicate on the "started_at" field.
|
||||||
|
func StartedAtLT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtLTE applies the LTE predicate on the "started_at" field.
|
||||||
|
func StartedAtLTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldStartedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtIsNil applies the IsNil predicate on the "started_at" field.
|
||||||
|
func StartedAtIsNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIsNull(FieldStartedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartedAtNotNil applies the NotNil predicate on the "started_at" field.
|
||||||
|
func StartedAtNotNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotNull(FieldStartedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtEQ applies the EQ predicate on the "finished_at" field.
|
||||||
|
func FinishedAtEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldEQ(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtNEQ applies the NEQ predicate on the "finished_at" field.
|
||||||
|
func FinishedAtNEQ(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNEQ(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtIn applies the In predicate on the "finished_at" field.
|
||||||
|
func FinishedAtIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIn(FieldFinishedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtNotIn applies the NotIn predicate on the "finished_at" field.
|
||||||
|
func FinishedAtNotIn(vs ...time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotIn(FieldFinishedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtGT applies the GT predicate on the "finished_at" field.
|
||||||
|
func FinishedAtGT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGT(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtGTE applies the GTE predicate on the "finished_at" field.
|
||||||
|
func FinishedAtGTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldGTE(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtLT applies the LT predicate on the "finished_at" field.
|
||||||
|
func FinishedAtLT(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLT(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtLTE applies the LTE predicate on the "finished_at" field.
|
||||||
|
func FinishedAtLTE(v time.Time) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldLTE(FieldFinishedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtIsNil applies the IsNil predicate on the "finished_at" field.
|
||||||
|
func FinishedAtIsNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldIsNull(FieldFinishedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FinishedAtNotNil applies the NotNil predicate on the "finished_at" field.
|
||||||
|
func FinishedAtNotNil() predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.FieldNotNull(FieldFinishedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.UsageCleanupTask) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.UsageCleanupTask) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.UsageCleanupTask) predicate.UsageCleanupTask {
|
||||||
|
return predicate.UsageCleanupTask(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
1190
backend/ent/usagecleanuptask_create.go
Normal file
1190
backend/ent/usagecleanuptask_create.go
Normal file
File diff suppressed because it is too large
Load Diff
88
backend/ent/usagecleanuptask_delete.go
Normal file
88
backend/ent/usagecleanuptask_delete.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UsageCleanupTaskDelete is the builder for deleting a UsageCleanupTask entity.
|
||||||
|
type UsageCleanupTaskDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UsageCleanupTaskMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
|
||||||
|
func (_d *UsageCleanupTaskDelete) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskDelete {
|
||||||
|
_d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *UsageCleanupTaskDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *UsageCleanupTaskDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := _d.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_d *UsageCleanupTaskDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(usagecleanuptask.Table, sqlgraph.NewFieldSpec(usagecleanuptask.FieldID, field.TypeInt64))
|
||||||
|
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
_d.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsageCleanupTaskDeleteOne is the builder for deleting a single UsageCleanupTask entity.
|
||||||
|
type UsageCleanupTaskDeleteOne struct {
|
||||||
|
_d *UsageCleanupTaskDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
|
||||||
|
func (_d *UsageCleanupTaskDeleteOne) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskDeleteOne {
|
||||||
|
_d._d.mutation.Where(ps...)
|
||||||
|
return _d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *UsageCleanupTaskDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := _d._d.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{usagecleanuptask.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *UsageCleanupTaskDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _d.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
564
backend/ent/usagecleanuptask_query.go
Normal file
564
backend/ent/usagecleanuptask_query.go
Normal file
@@ -0,0 +1,564 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UsageCleanupTaskQuery is the builder for querying UsageCleanupTask entities.
|
||||||
|
type UsageCleanupTaskQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []usagecleanuptask.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.UsageCleanupTask
|
||||||
|
modifiers []func(*sql.Selector)
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the UsageCleanupTaskQuery builder.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskQuery {
|
||||||
|
_q.predicates = append(_q.predicates, ps...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Limit(limit int) *UsageCleanupTaskQuery {
|
||||||
|
_q.ctx.Limit = &limit
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Offset(offset int) *UsageCleanupTaskQuery {
|
||||||
|
_q.ctx.Offset = &offset
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Unique(unique bool) *UsageCleanupTaskQuery {
|
||||||
|
_q.ctx.Unique = &unique
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Order(o ...usagecleanuptask.OrderOption) *UsageCleanupTaskQuery {
|
||||||
|
_q.order = append(_q.order, o...)
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first UsageCleanupTask entity from the query.
|
||||||
|
// Returns a *NotFoundError when no UsageCleanupTask was found.
|
||||||
|
func (_q *UsageCleanupTaskQuery) First(ctx context.Context) (*UsageCleanupTask, error) {
|
||||||
|
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{usagecleanuptask.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) FirstX(ctx context.Context) *UsageCleanupTask {
|
||||||
|
node, err := _q.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first UsageCleanupTask ID from the query.
|
||||||
|
// Returns a *NotFoundError when no UsageCleanupTask ID was found.
|
||||||
|
func (_q *UsageCleanupTaskQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{usagecleanuptask.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single UsageCleanupTask entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one UsageCleanupTask entity is found.
|
||||||
|
// Returns a *NotFoundError when no UsageCleanupTask entities are found.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Only(ctx context.Context) (*UsageCleanupTask, error) {
|
||||||
|
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{usagecleanuptask.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{usagecleanuptask.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) OnlyX(ctx context.Context) *UsageCleanupTask {
|
||||||
|
node, err := _q.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only UsageCleanupTask ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one UsageCleanupTask ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *UsageCleanupTaskQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{usagecleanuptask.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{usagecleanuptask.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := _q.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of UsageCleanupTasks.
|
||||||
|
func (_q *UsageCleanupTaskQuery) All(ctx context.Context) ([]*UsageCleanupTask, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*UsageCleanupTask, *UsageCleanupTaskQuery]()
|
||||||
|
return withInterceptors[[]*UsageCleanupTask](ctx, _q, qr, _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) AllX(ctx context.Context) []*UsageCleanupTask {
|
||||||
|
nodes, err := _q.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of UsageCleanupTask IDs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||||
|
if _q.ctx.Unique == nil && _q.path != nil {
|
||||||
|
_q.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||||
|
if err = _q.Select(usagecleanuptask.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := _q.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||||
|
if err := _q.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, _q, querierCount[*UsageCleanupTaskQuery](), _q.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := _q.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := _q.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (_q *UsageCleanupTaskQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := _q.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the UsageCleanupTaskQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Clone() *UsageCleanupTaskQuery {
|
||||||
|
if _q == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &UsageCleanupTaskQuery{
|
||||||
|
config: _q.config,
|
||||||
|
ctx: _q.ctx.Clone(),
|
||||||
|
order: append([]usagecleanuptask.OrderOption{}, _q.order...),
|
||||||
|
inters: append([]Interceptor{}, _q.inters...),
|
||||||
|
predicates: append([]predicate.UsageCleanupTask{}, _q.predicates...),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(),
|
||||||
|
path: _q.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.UsageCleanupTask.Query().
|
||||||
|
// GroupBy(usagecleanuptask.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *UsageCleanupTaskQuery) GroupBy(field string, fields ...string) *UsageCleanupTaskGroupBy {
|
||||||
|
_q.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &UsageCleanupTaskGroupBy{build: _q}
|
||||||
|
grbuild.flds = &_q.ctx.Fields
|
||||||
|
grbuild.label = usagecleanuptask.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.UsageCleanupTask.Query().
|
||||||
|
// Select(usagecleanuptask.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *UsageCleanupTaskQuery) Select(fields ...string) *UsageCleanupTaskSelect {
|
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||||
|
sbuild := &UsageCleanupTaskSelect{UsageCleanupTaskQuery: _q}
|
||||||
|
sbuild.label = usagecleanuptask.Label
|
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a UsageCleanupTaskSelect configured with the given aggregations.
|
||||||
|
func (_q *UsageCleanupTaskQuery) Aggregate(fns ...AggregateFunc) *UsageCleanupTaskSelect {
|
||||||
|
return _q.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UsageCleanupTaskQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range _q.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, _q); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range _q.ctx.Fields {
|
||||||
|
if !usagecleanuptask.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _q.path != nil {
|
||||||
|
prev, err := _q.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_q.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UsageCleanupTaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*UsageCleanupTask, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*UsageCleanupTask{}
|
||||||
|
_spec = _q.querySpec()
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*UsageCleanupTask).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &UsageCleanupTask{config: _q.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
if len(_q.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = _q.modifiers
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UsageCleanupTaskQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := _q.querySpec()
|
||||||
|
if len(_q.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = _q.modifiers
|
||||||
|
}
|
||||||
|
_spec.Node.Columns = _q.ctx.Fields
|
||||||
|
if len(_q.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UsageCleanupTaskQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(usagecleanuptask.Table, usagecleanuptask.Columns, sqlgraph.NewFieldSpec(usagecleanuptask.FieldID, field.TypeInt64))
|
||||||
|
_spec.From = _q.sql
|
||||||
|
if unique := _q.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if _q.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, usagecleanuptask.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != usagecleanuptask.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _q.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := _q.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_q *UsageCleanupTaskQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(_q.driver.Dialect())
|
||||||
|
t1 := builder.Table(usagecleanuptask.Table)
|
||||||
|
columns := _q.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = usagecleanuptask.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if _q.sql != nil {
|
||||||
|
selector = _q.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, m := range _q.modifiers {
|
||||||
|
m(selector)
|
||||||
|
}
|
||||||
|
for _, p := range _q.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range _q.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := _q.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := _q.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||||
|
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||||
|
// either committed or rolled-back.
|
||||||
|
func (_q *UsageCleanupTaskQuery) ForUpdate(opts ...sql.LockOption) *UsageCleanupTaskQuery {
|
||||||
|
if _q.driver.Dialect() == dialect.Postgres {
|
||||||
|
_q.Unique(false)
|
||||||
|
}
|
||||||
|
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||||
|
s.ForUpdate(opts...)
|
||||||
|
})
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||||
|
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||||
|
// until your transaction commits.
|
||||||
|
func (_q *UsageCleanupTaskQuery) ForShare(opts ...sql.LockOption) *UsageCleanupTaskQuery {
|
||||||
|
if _q.driver.Dialect() == dialect.Postgres {
|
||||||
|
_q.Unique(false)
|
||||||
|
}
|
||||||
|
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||||
|
s.ForShare(opts...)
|
||||||
|
})
|
||||||
|
return _q
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsageCleanupTaskGroupBy is the group-by builder for UsageCleanupTask entities.
|
||||||
|
type UsageCleanupTaskGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *UsageCleanupTaskQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *UsageCleanupTaskGroupBy) Aggregate(fns ...AggregateFunc) *UsageCleanupTaskGroupBy {
|
||||||
|
_g.fns = append(_g.fns, fns...)
|
||||||
|
return _g
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *UsageCleanupTaskGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*UsageCleanupTaskQuery, *UsageCleanupTaskGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_g *UsageCleanupTaskGroupBy) sqlScan(ctx context.Context, root *UsageCleanupTaskQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(_g.fns))
|
||||||
|
for _, fn := range _g.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||||
|
for _, f := range *_g.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsageCleanupTaskSelect is the builder for selecting fields of UsageCleanupTask entities.
|
||||||
|
type UsageCleanupTaskSelect struct {
|
||||||
|
*UsageCleanupTaskQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *UsageCleanupTaskSelect) Aggregate(fns ...AggregateFunc) *UsageCleanupTaskSelect {
|
||||||
|
_s.fns = append(_s.fns, fns...)
|
||||||
|
return _s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *UsageCleanupTaskSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||||
|
if err := _s.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*UsageCleanupTaskQuery, *UsageCleanupTaskSelect](ctx, _s.UsageCleanupTaskQuery, _s, _s.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_s *UsageCleanupTaskSelect) sqlScan(ctx context.Context, root *UsageCleanupTaskQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(_s.fns))
|
||||||
|
for _, fn := range _s.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*_s.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
702
backend/ent/usagecleanuptask_update.go
Normal file
702
backend/ent/usagecleanuptask_update.go
Normal file
@@ -0,0 +1,702 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/dialect/sql/sqljson"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UsageCleanupTaskUpdate is the builder for updating UsageCleanupTask entities.
|
||||||
|
type UsageCleanupTaskUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UsageCleanupTaskMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetUpdatedAt(v time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetStatus(v string) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetStatus(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableStatus(v *string) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFilters sets the "filters" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetFilters(v json.RawMessage) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetFilters(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendFilters appends value to the "filters" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) AppendFilters(v json.RawMessage) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.AppendFilters(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedBy sets the "created_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetCreatedBy(v int64) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ResetCreatedBy()
|
||||||
|
_u.mutation.SetCreatedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableCreatedBy(v *int64) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCreatedBy(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCreatedBy adds value to the "created_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) AddCreatedBy(v int64) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.AddCreatedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedRows sets the "deleted_rows" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetDeletedRows(v int64) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ResetDeletedRows()
|
||||||
|
_u.mutation.SetDeletedRows(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableDeletedRows(v *int64) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetDeletedRows(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDeletedRows adds value to the "deleted_rows" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) AddDeletedRows(v int64) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.AddDeletedRows(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetErrorMessage sets the "error_message" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetErrorMessage(v string) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetErrorMessage(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableErrorMessage(v *string) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetErrorMessage(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearErrorMessage clears the value of the "error_message" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) ClearErrorMessage() *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ClearErrorMessage()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCanceledBy sets the "canceled_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetCanceledBy(v int64) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ResetCanceledBy()
|
||||||
|
_u.mutation.SetCanceledBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableCanceledBy(v *int64) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCanceledBy(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCanceledBy adds value to the "canceled_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) AddCanceledBy(v int64) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.AddCanceledBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCanceledBy clears the value of the "canceled_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) ClearCanceledBy() *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ClearCanceledBy()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCanceledAt sets the "canceled_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetCanceledAt(v time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetCanceledAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableCanceledAt(v *time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCanceledAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCanceledAt clears the value of the "canceled_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) ClearCanceledAt() *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ClearCanceledAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStartedAt sets the "started_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetStartedAt(v time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetStartedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableStartedAt(v *time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStartedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearStartedAt clears the value of the "started_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) ClearStartedAt() *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ClearStartedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFinishedAt sets the "finished_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetFinishedAt(v time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.SetFinishedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SetNillableFinishedAt(v *time.Time) *UsageCleanupTaskUpdate {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetFinishedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearFinishedAt clears the value of the "finished_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) ClearFinishedAt() *UsageCleanupTaskUpdate {
|
||||||
|
_u.mutation.ClearFinishedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UsageCleanupTaskMutation object of the builder.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) Mutation() *UsageCleanupTaskMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := usagecleanuptask.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *UsageCleanupTaskUpdate) check() error {
|
||||||
|
if v, ok := _u.mutation.Status(); ok {
|
||||||
|
if err := usagecleanuptask.StatusValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UsageCleanupTask.status": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *UsageCleanupTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(usagecleanuptask.Table, usagecleanuptask.Columns, sqlgraph.NewFieldSpec(usagecleanuptask.FieldID, field.TypeInt64))
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldStatus, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Filters(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldFilters, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AppendedFilters(); ok {
|
||||||
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||||
|
sqljson.Append(u, usagecleanuptask.FieldFilters, value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CreatedBy(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedCreatedBy(); ok {
|
||||||
|
_spec.AddField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.DeletedRows(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedDeletedRows(); ok {
|
||||||
|
_spec.AddField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ErrorMessage(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldErrorMessage, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ErrorMessageCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldErrorMessage, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CanceledBy(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedCanceledBy(); ok {
|
||||||
|
_spec.AddField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.CanceledByCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldCanceledBy, field.TypeInt64)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CanceledAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldCanceledAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.CanceledAtCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldCanceledAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.StartedAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldStartedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.StartedAtCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldStartedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.FinishedAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldFinishedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.FinishedAtCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldFinishedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{usagecleanuptask.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsageCleanupTaskUpdateOne is the builder for updating a single UsageCleanupTask entity.
|
||||||
|
type UsageCleanupTaskUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UsageCleanupTaskMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetUpdatedAt(v time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the "status" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetStatus(v string) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetStatus(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableStatus(v *string) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStatus(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFilters sets the "filters" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetFilters(v json.RawMessage) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetFilters(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendFilters appends value to the "filters" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) AppendFilters(v json.RawMessage) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.AppendFilters(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedBy sets the "created_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetCreatedBy(v int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ResetCreatedBy()
|
||||||
|
_u.mutation.SetCreatedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableCreatedBy(v *int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCreatedBy(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCreatedBy adds value to the "created_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) AddCreatedBy(v int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.AddCreatedBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedRows sets the "deleted_rows" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetDeletedRows(v int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ResetDeletedRows()
|
||||||
|
_u.mutation.SetDeletedRows(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableDeletedRows(v *int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetDeletedRows(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDeletedRows adds value to the "deleted_rows" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) AddDeletedRows(v int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.AddDeletedRows(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetErrorMessage sets the "error_message" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetErrorMessage(v string) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetErrorMessage(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableErrorMessage(v *string) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetErrorMessage(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearErrorMessage clears the value of the "error_message" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) ClearErrorMessage() *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ClearErrorMessage()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCanceledBy sets the "canceled_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetCanceledBy(v int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ResetCanceledBy()
|
||||||
|
_u.mutation.SetCanceledBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableCanceledBy(v *int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCanceledBy(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCanceledBy adds value to the "canceled_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) AddCanceledBy(v int64) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.AddCanceledBy(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCanceledBy clears the value of the "canceled_by" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) ClearCanceledBy() *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ClearCanceledBy()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCanceledAt sets the "canceled_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetCanceledAt(v time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetCanceledAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableCanceledAt(v *time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetCanceledAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCanceledAt clears the value of the "canceled_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) ClearCanceledAt() *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ClearCanceledAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStartedAt sets the "started_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetStartedAt(v time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetStartedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableStartedAt(v *time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetStartedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearStartedAt clears the value of the "started_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) ClearStartedAt() *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ClearStartedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFinishedAt sets the "finished_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetFinishedAt(v time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.SetFinishedAt(v)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SetNillableFinishedAt(v *time.Time) *UsageCleanupTaskUpdateOne {
|
||||||
|
if v != nil {
|
||||||
|
_u.SetFinishedAt(*v)
|
||||||
|
}
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearFinishedAt clears the value of the "finished_at" field.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) ClearFinishedAt() *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.ClearFinishedAt()
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UsageCleanupTaskMutation object of the builder.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) Mutation() *UsageCleanupTaskMutation {
|
||||||
|
return _u.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) Where(ps ...predicate.UsageCleanupTask) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.mutation.Where(ps...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) Select(field string, fields ...string) *UsageCleanupTaskUpdateOne {
|
||||||
|
_u.fields = append([]string{field}, fields...)
|
||||||
|
return _u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated UsageCleanupTask entity.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) Save(ctx context.Context) (*UsageCleanupTask, error) {
|
||||||
|
_u.defaults()
|
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) SaveX(ctx context.Context) *UsageCleanupTask {
|
||||||
|
node, err := _u.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := _u.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := _u.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) defaults() {
|
||||||
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||||
|
v := usagecleanuptask.UpdateDefaultUpdatedAt()
|
||||||
|
_u.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) check() error {
|
||||||
|
if v, ok := _u.mutation.Status(); ok {
|
||||||
|
if err := usagecleanuptask.StatusValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UsageCleanupTask.status": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_u *UsageCleanupTaskUpdateOne) sqlSave(ctx context.Context) (_node *UsageCleanupTask, err error) {
|
||||||
|
if err := _u.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(usagecleanuptask.Table, usagecleanuptask.Columns, sqlgraph.NewFieldSpec(usagecleanuptask.FieldID, field.TypeInt64))
|
||||||
|
id, ok := _u.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageCleanupTask.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := _u.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, usagecleanuptask.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !usagecleanuptask.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != usagecleanuptask.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Status(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldStatus, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.Filters(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldFilters, field.TypeJSON, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AppendedFilters(); ok {
|
||||||
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||||
|
sqljson.Append(u, usagecleanuptask.FieldFilters, value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CreatedBy(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedCreatedBy(); ok {
|
||||||
|
_spec.AddField(usagecleanuptask.FieldCreatedBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.DeletedRows(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedDeletedRows(); ok {
|
||||||
|
_spec.AddField(usagecleanuptask.FieldDeletedRows, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.ErrorMessage(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldErrorMessage, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.ErrorMessageCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldErrorMessage, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CanceledBy(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.AddedCanceledBy(); ok {
|
||||||
|
_spec.AddField(usagecleanuptask.FieldCanceledBy, field.TypeInt64, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.CanceledByCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldCanceledBy, field.TypeInt64)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.CanceledAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldCanceledAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.CanceledAtCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldCanceledAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.StartedAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldStartedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.StartedAtCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldStartedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := _u.mutation.FinishedAt(); ok {
|
||||||
|
_spec.SetField(usagecleanuptask.FieldFinishedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if _u.mutation.FinishedAtCleared() {
|
||||||
|
_spec.ClearField(usagecleanuptask.FieldFinishedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
_node = &UsageCleanupTask{config: _u.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{usagecleanuptask.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_u.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@@ -98,6 +98,7 @@ require (
|
|||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/morikuni/aec v1.0.0 // indirect
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
|
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/opencontainers/image-spec v1.1.1 // indirect
|
github.com/opencontainers/image-spec v1.1.1 // indirect
|
||||||
@@ -108,6 +109,7 @@ require (
|
|||||||
github.com/quic-go/qpack v0.6.0 // indirect
|
github.com/quic-go/qpack v0.6.0 // indirect
|
||||||
github.com/quic-go/quic-go v0.57.1 // indirect
|
github.com/quic-go/quic-go v0.57.1 // indirect
|
||||||
github.com/refraction-networking/utls v1.8.1 // indirect
|
github.com/refraction-networking/utls v1.8.1 // indirect
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||||
@@ -140,7 +142,7 @@ require (
|
|||||||
go.uber.org/automaxprocs v1.6.0 // indirect
|
go.uber.org/automaxprocs v1.6.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
golang.org/x/arch v0.3.0 // indirect
|
golang.org/x/arch v0.3.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
|
||||||
golang.org/x/mod v0.30.0 // indirect
|
golang.org/x/mod v0.30.0 // indirect
|
||||||
golang.org/x/sys v0.39.0 // indirect
|
golang.org/x/sys v0.39.0 // indirect
|
||||||
golang.org/x/text v0.32.0 // indirect
|
golang.org/x/text v0.32.0 // indirect
|
||||||
@@ -149,4 +151,8 @@ require (
|
|||||||
google.golang.org/grpc v1.75.1 // indirect
|
google.golang.org/grpc v1.75.1 // indirect
|
||||||
google.golang.org/protobuf v1.36.10 // indirect
|
google.golang.org/protobuf v1.36.10 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
modernc.org/libc v1.67.6 // indirect
|
||||||
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
|
modernc.org/memory v1.11.0 // indirect
|
||||||
|
modernc.org/sqlite v1.44.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -200,6 +200,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
|||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
|
||||||
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
|
||||||
|
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||||
|
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||||
@@ -225,6 +227,8 @@ github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4Vi
|
|||||||
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
|
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
|
||||||
github.com/refraction-networking/utls v1.8.1 h1:yNY1kapmQU8JeM1sSw2H2asfTIwWxIkrMJI0pRUOCAo=
|
github.com/refraction-networking/utls v1.8.1 h1:yNY1kapmQU8JeM1sSw2H2asfTIwWxIkrMJI0pRUOCAo=
|
||||||
github.com/refraction-networking/utls v1.8.1/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
github.com/refraction-networking/utls v1.8.1/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
@@ -339,6 +343,8 @@ golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
|||||||
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||||
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
|
||||||
|
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
|
||||||
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
|
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
|
||||||
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
|
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
|
||||||
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||||
@@ -366,6 +372,7 @@ golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
|
|||||||
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
|
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
|
||||||
golang.org/x/tools/go/expect v0.1.0-deprecated h1:jY2C5HGYR5lqex3gEniOQL0r7Dq5+VGVgY1nudX5lXY=
|
golang.org/x/tools/go/expect v0.1.0-deprecated h1:jY2C5HGYR5lqex3gEniOQL0r7Dq5+VGVgY1nudX5lXY=
|
||||||
golang.org/x/tools/go/expect v0.1.0-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
|
golang.org/x/tools/go/expect v0.1.0-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
|
||||||
|
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
|
||||||
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
|
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
|
||||||
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
|
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -388,4 +395,12 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
||||||
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
||||||
|
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
|
||||||
|
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
|
||||||
|
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||||
|
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||||
|
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||||
|
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||||
|
modernc.org/sqlite v1.44.1 h1:qybx/rNpfQipX/t47OxbHmkkJuv2JWifCMH8SVUiDas=
|
||||||
|
modernc.org/sqlite v1.44.1/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package admin
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|||||||
@@ -7,43 +7,41 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
dbusagecleanuptask "github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
||||||
"github.com/Wei-Shaw/sub2api/internal/service"
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
type usageCleanupRepository struct {
|
type usageCleanupRepository struct {
|
||||||
sql sqlExecutor
|
client *dbent.Client
|
||||||
|
sql sqlExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUsageCleanupRepository(sqlDB *sql.DB) service.UsageCleanupRepository {
|
func NewUsageCleanupRepository(client *dbent.Client, sqlDB *sql.DB) service.UsageCleanupRepository {
|
||||||
return &usageCleanupRepository{sql: sqlDB}
|
return newUsageCleanupRepositoryWithSQL(client, sqlDB)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newUsageCleanupRepositoryWithSQL(client *dbent.Client, sqlq sqlExecutor) *usageCleanupRepository {
|
||||||
|
return &usageCleanupRepository{client: client, sql: sqlq}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) CreateTask(ctx context.Context, task *service.UsageCleanupTask) error {
|
func (r *usageCleanupRepository) CreateTask(ctx context.Context, task *service.UsageCleanupTask) error {
|
||||||
if task == nil {
|
if task == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
filtersJSON, err := json.Marshal(task.Filters)
|
if r.client != nil {
|
||||||
if err != nil {
|
return r.createTaskWithEnt(ctx, task)
|
||||||
return fmt.Errorf("marshal cleanup filters: %w", err)
|
|
||||||
}
|
}
|
||||||
query := `
|
return r.createTaskWithSQL(ctx, task)
|
||||||
INSERT INTO usage_cleanup_tasks (
|
|
||||||
status,
|
|
||||||
filters,
|
|
||||||
created_by,
|
|
||||||
deleted_rows
|
|
||||||
) VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING id, created_at, updated_at
|
|
||||||
`
|
|
||||||
if err := scanSingleRow(ctx, r.sql, query, []any{task.Status, filtersJSON, task.CreatedBy, task.DeletedRows}, &task.ID, &task.CreatedAt, &task.UpdatedAt); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) ListTasks(ctx context.Context, params pagination.PaginationParams) ([]service.UsageCleanupTask, *pagination.PaginationResult, error) {
|
func (r *usageCleanupRepository) ListTasks(ctx context.Context, params pagination.PaginationParams) ([]service.UsageCleanupTask, *pagination.PaginationResult, error) {
|
||||||
|
if r.client != nil {
|
||||||
|
return r.listTasksWithEnt(ctx, params)
|
||||||
|
}
|
||||||
var total int64
|
var total int64
|
||||||
if err := scanSingleRow(ctx, r.sql, "SELECT COUNT(*) FROM usage_cleanup_tasks", nil, &total); err != nil {
|
if err := scanSingleRow(ctx, r.sql, "SELECT COUNT(*) FROM usage_cleanup_tasks", nil, &total); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@@ -57,14 +55,14 @@ func (r *usageCleanupRepository) ListTasks(ctx context.Context, params paginatio
|
|||||||
canceled_by, canceled_at,
|
canceled_by, canceled_at,
|
||||||
started_at, finished_at, created_at, updated_at
|
started_at, finished_at, created_at, updated_at
|
||||||
FROM usage_cleanup_tasks
|
FROM usage_cleanup_tasks
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC, id DESC
|
||||||
LIMIT $1 OFFSET $2
|
LIMIT $1 OFFSET $2
|
||||||
`
|
`
|
||||||
rows, err := r.sql.QueryContext(ctx, query, params.Limit(), params.Offset())
|
rows, err := r.sql.QueryContext(ctx, query, params.Limit(), params.Offset())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer func() { _ = rows.Close() }()
|
||||||
|
|
||||||
tasks := make([]service.UsageCleanupTask, 0)
|
tasks := make([]service.UsageCleanupTask, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -194,6 +192,9 @@ func (r *usageCleanupRepository) ClaimNextPendingTask(ctx context.Context, stale
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) GetTaskStatus(ctx context.Context, taskID int64) (string, error) {
|
func (r *usageCleanupRepository) GetTaskStatus(ctx context.Context, taskID int64) (string, error) {
|
||||||
|
if r.client != nil {
|
||||||
|
return r.getTaskStatusWithEnt(ctx, taskID)
|
||||||
|
}
|
||||||
var status string
|
var status string
|
||||||
if err := scanSingleRow(ctx, r.sql, "SELECT status FROM usage_cleanup_tasks WHERE id = $1", []any{taskID}, &status); err != nil {
|
if err := scanSingleRow(ctx, r.sql, "SELECT status FROM usage_cleanup_tasks WHERE id = $1", []any{taskID}, &status); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -202,6 +203,9 @@ func (r *usageCleanupRepository) GetTaskStatus(ctx context.Context, taskID int64
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) UpdateTaskProgress(ctx context.Context, taskID int64, deletedRows int64) error {
|
func (r *usageCleanupRepository) UpdateTaskProgress(ctx context.Context, taskID int64, deletedRows int64) error {
|
||||||
|
if r.client != nil {
|
||||||
|
return r.updateTaskProgressWithEnt(ctx, taskID, deletedRows)
|
||||||
|
}
|
||||||
query := `
|
query := `
|
||||||
UPDATE usage_cleanup_tasks
|
UPDATE usage_cleanup_tasks
|
||||||
SET deleted_rows = $1,
|
SET deleted_rows = $1,
|
||||||
@@ -213,6 +217,9 @@ func (r *usageCleanupRepository) UpdateTaskProgress(ctx context.Context, taskID
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) CancelTask(ctx context.Context, taskID int64, canceledBy int64) (bool, error) {
|
func (r *usageCleanupRepository) CancelTask(ctx context.Context, taskID int64, canceledBy int64) (bool, error) {
|
||||||
|
if r.client != nil {
|
||||||
|
return r.cancelTaskWithEnt(ctx, taskID, canceledBy)
|
||||||
|
}
|
||||||
query := `
|
query := `
|
||||||
UPDATE usage_cleanup_tasks
|
UPDATE usage_cleanup_tasks
|
||||||
SET status = $1,
|
SET status = $1,
|
||||||
@@ -243,6 +250,9 @@ func (r *usageCleanupRepository) CancelTask(ctx context.Context, taskID int64, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) MarkTaskSucceeded(ctx context.Context, taskID int64, deletedRows int64) error {
|
func (r *usageCleanupRepository) MarkTaskSucceeded(ctx context.Context, taskID int64, deletedRows int64) error {
|
||||||
|
if r.client != nil {
|
||||||
|
return r.markTaskSucceededWithEnt(ctx, taskID, deletedRows)
|
||||||
|
}
|
||||||
query := `
|
query := `
|
||||||
UPDATE usage_cleanup_tasks
|
UPDATE usage_cleanup_tasks
|
||||||
SET status = $1,
|
SET status = $1,
|
||||||
@@ -256,6 +266,9 @@ func (r *usageCleanupRepository) MarkTaskSucceeded(ctx context.Context, taskID i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *usageCleanupRepository) MarkTaskFailed(ctx context.Context, taskID int64, deletedRows int64, errorMsg string) error {
|
func (r *usageCleanupRepository) MarkTaskFailed(ctx context.Context, taskID int64, deletedRows int64, errorMsg string) error {
|
||||||
|
if r.client != nil {
|
||||||
|
return r.markTaskFailedWithEnt(ctx, taskID, deletedRows, errorMsg)
|
||||||
|
}
|
||||||
query := `
|
query := `
|
||||||
UPDATE usage_cleanup_tasks
|
UPDATE usage_cleanup_tasks
|
||||||
SET status = $1,
|
SET status = $1,
|
||||||
@@ -295,7 +308,7 @@ func (r *usageCleanupRepository) DeleteUsageLogsBatch(ctx context.Context, filte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer func() { _ = rows.Close() }()
|
||||||
|
|
||||||
var deleted int64
|
var deleted int64
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@@ -357,7 +370,182 @@ func buildUsageCleanupWhere(filters service.UsageCleanupFilters) (string, []any)
|
|||||||
if filters.BillingType != nil {
|
if filters.BillingType != nil {
|
||||||
conditions = append(conditions, fmt.Sprintf("billing_type = $%d", idx))
|
conditions = append(conditions, fmt.Sprintf("billing_type = $%d", idx))
|
||||||
args = append(args, *filters.BillingType)
|
args = append(args, *filters.BillingType)
|
||||||
idx++
|
|
||||||
}
|
}
|
||||||
return strings.Join(conditions, " AND "), args
|
return strings.Join(conditions, " AND "), args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) createTaskWithEnt(ctx context.Context, task *service.UsageCleanupTask) error {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
filtersJSON, err := json.Marshal(task.Filters)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("marshal cleanup filters: %w", err)
|
||||||
|
}
|
||||||
|
created, err := client.UsageCleanupTask.
|
||||||
|
Create().
|
||||||
|
SetStatus(task.Status).
|
||||||
|
SetFilters(json.RawMessage(filtersJSON)).
|
||||||
|
SetCreatedBy(task.CreatedBy).
|
||||||
|
SetDeletedRows(task.DeletedRows).
|
||||||
|
Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
task.ID = created.ID
|
||||||
|
task.CreatedAt = created.CreatedAt
|
||||||
|
task.UpdatedAt = created.UpdatedAt
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) createTaskWithSQL(ctx context.Context, task *service.UsageCleanupTask) error {
|
||||||
|
filtersJSON, err := json.Marshal(task.Filters)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("marshal cleanup filters: %w", err)
|
||||||
|
}
|
||||||
|
query := `
|
||||||
|
INSERT INTO usage_cleanup_tasks (
|
||||||
|
status,
|
||||||
|
filters,
|
||||||
|
created_by,
|
||||||
|
deleted_rows
|
||||||
|
) VALUES ($1, $2, $3, $4)
|
||||||
|
RETURNING id, created_at, updated_at
|
||||||
|
`
|
||||||
|
if err := scanSingleRow(ctx, r.sql, query, []any{task.Status, filtersJSON, task.CreatedBy, task.DeletedRows}, &task.ID, &task.CreatedAt, &task.UpdatedAt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) listTasksWithEnt(ctx context.Context, params pagination.PaginationParams) ([]service.UsageCleanupTask, *pagination.PaginationResult, error) {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
query := client.UsageCleanupTask.Query()
|
||||||
|
total, err := query.Clone().Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if total == 0 {
|
||||||
|
return []service.UsageCleanupTask{}, paginationResultFromTotal(0, params), nil
|
||||||
|
}
|
||||||
|
rows, err := query.
|
||||||
|
Order(dbent.Desc(dbusagecleanuptask.FieldCreatedAt), dbent.Desc(dbusagecleanuptask.FieldID)).
|
||||||
|
Offset(params.Offset()).
|
||||||
|
Limit(params.Limit()).
|
||||||
|
All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
tasks := make([]service.UsageCleanupTask, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
task, err := usageCleanupTaskFromEnt(row)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
tasks = append(tasks, task)
|
||||||
|
}
|
||||||
|
return tasks, paginationResultFromTotal(int64(total), params), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) getTaskStatusWithEnt(ctx context.Context, taskID int64) (string, error) {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
task, err := client.UsageCleanupTask.Query().
|
||||||
|
Where(dbusagecleanuptask.IDEQ(taskID)).
|
||||||
|
Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
if dbent.IsNotFound(err) {
|
||||||
|
return "", sql.ErrNoRows
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return task.Status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) updateTaskProgressWithEnt(ctx context.Context, taskID int64, deletedRows int64) error {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
now := time.Now()
|
||||||
|
_, err := client.UsageCleanupTask.Update().
|
||||||
|
Where(dbusagecleanuptask.IDEQ(taskID)).
|
||||||
|
SetDeletedRows(deletedRows).
|
||||||
|
SetUpdatedAt(now).
|
||||||
|
Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) cancelTaskWithEnt(ctx context.Context, taskID int64, canceledBy int64) (bool, error) {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
now := time.Now()
|
||||||
|
affected, err := client.UsageCleanupTask.Update().
|
||||||
|
Where(
|
||||||
|
dbusagecleanuptask.IDEQ(taskID),
|
||||||
|
dbusagecleanuptask.StatusIn(service.UsageCleanupStatusPending, service.UsageCleanupStatusRunning),
|
||||||
|
).
|
||||||
|
SetStatus(service.UsageCleanupStatusCanceled).
|
||||||
|
SetCanceledBy(canceledBy).
|
||||||
|
SetCanceledAt(now).
|
||||||
|
SetFinishedAt(now).
|
||||||
|
ClearErrorMessage().
|
||||||
|
SetUpdatedAt(now).
|
||||||
|
Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return affected > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) markTaskSucceededWithEnt(ctx context.Context, taskID int64, deletedRows int64) error {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
now := time.Now()
|
||||||
|
_, err := client.UsageCleanupTask.Update().
|
||||||
|
Where(dbusagecleanuptask.IDEQ(taskID)).
|
||||||
|
SetStatus(service.UsageCleanupStatusSucceeded).
|
||||||
|
SetDeletedRows(deletedRows).
|
||||||
|
SetFinishedAt(now).
|
||||||
|
SetUpdatedAt(now).
|
||||||
|
Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *usageCleanupRepository) markTaskFailedWithEnt(ctx context.Context, taskID int64, deletedRows int64, errorMsg string) error {
|
||||||
|
client := clientFromContext(ctx, r.client)
|
||||||
|
now := time.Now()
|
||||||
|
_, err := client.UsageCleanupTask.Update().
|
||||||
|
Where(dbusagecleanuptask.IDEQ(taskID)).
|
||||||
|
SetStatus(service.UsageCleanupStatusFailed).
|
||||||
|
SetDeletedRows(deletedRows).
|
||||||
|
SetErrorMessage(errorMsg).
|
||||||
|
SetFinishedAt(now).
|
||||||
|
SetUpdatedAt(now).
|
||||||
|
Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func usageCleanupTaskFromEnt(row *dbent.UsageCleanupTask) (service.UsageCleanupTask, error) {
|
||||||
|
task := service.UsageCleanupTask{
|
||||||
|
ID: row.ID,
|
||||||
|
Status: row.Status,
|
||||||
|
CreatedBy: row.CreatedBy,
|
||||||
|
DeletedRows: row.DeletedRows,
|
||||||
|
CreatedAt: row.CreatedAt,
|
||||||
|
UpdatedAt: row.UpdatedAt,
|
||||||
|
}
|
||||||
|
if len(row.Filters) > 0 {
|
||||||
|
if err := json.Unmarshal(row.Filters, &task.Filters); err != nil {
|
||||||
|
return service.UsageCleanupTask{}, fmt.Errorf("parse cleanup filters: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if row.ErrorMessage != nil {
|
||||||
|
task.ErrorMsg = row.ErrorMessage
|
||||||
|
}
|
||||||
|
if row.CanceledBy != nil {
|
||||||
|
task.CanceledBy = row.CanceledBy
|
||||||
|
}
|
||||||
|
if row.CanceledAt != nil {
|
||||||
|
task.CanceledAt = row.CanceledAt
|
||||||
|
}
|
||||||
|
if row.StartedAt != nil {
|
||||||
|
task.StartedAt = row.StartedAt
|
||||||
|
}
|
||||||
|
if row.FinishedAt != nil {
|
||||||
|
task.FinishedAt = row.FinishedAt
|
||||||
|
}
|
||||||
|
return task, nil
|
||||||
|
}
|
||||||
|
|||||||
251
backend/internal/repository/usage_cleanup_repo_ent_test.go
Normal file
251
backend/internal/repository/usage_cleanup_repo_ent_test.go
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
dbent "github.com/Wei-Shaw/sub2api/ent"
|
||||||
|
"github.com/Wei-Shaw/sub2api/ent/enttest"
|
||||||
|
dbusagecleanuptask "github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
||||||
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
entsql "entgo.io/ent/dialect/sql"
|
||||||
|
_ "modernc.org/sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newUsageCleanupEntRepo(t *testing.T) (*usageCleanupRepository, *dbent.Client) {
|
||||||
|
t.Helper()
|
||||||
|
db, err := sql.Open("sqlite", "file:usage_cleanup?mode=memory&cache=shared")
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Cleanup(func() { _ = db.Close() })
|
||||||
|
_, err = db.Exec("PRAGMA foreign_keys = ON")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
drv := entsql.OpenDB(dialect.SQLite, db)
|
||||||
|
client := enttest.NewClient(t, enttest.WithOptions(dbent.Driver(drv)))
|
||||||
|
t.Cleanup(func() { _ = client.Close() })
|
||||||
|
|
||||||
|
repo := &usageCleanupRepository{client: client, sql: db}
|
||||||
|
return repo, client
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntCreateAndList(t *testing.T) {
|
||||||
|
repo, _ := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
start := time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||||
|
end := start.Add(24 * time.Hour)
|
||||||
|
task := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusPending,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: start, EndTime: end},
|
||||||
|
CreatedBy: 9,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task))
|
||||||
|
require.NotZero(t, task.ID)
|
||||||
|
|
||||||
|
task2 := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusRunning,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: start.Add(-24 * time.Hour), EndTime: end.Add(-24 * time.Hour)},
|
||||||
|
CreatedBy: 10,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task2))
|
||||||
|
|
||||||
|
tasks, result, err := repo.ListTasks(context.Background(), pagination.PaginationParams{Page: 1, PageSize: 10})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, tasks, 2)
|
||||||
|
require.Equal(t, int64(2), result.Total)
|
||||||
|
require.Greater(t, tasks[0].ID, tasks[1].ID)
|
||||||
|
require.Equal(t, start, tasks[1].Filters.StartTime)
|
||||||
|
require.Equal(t, end, tasks[1].Filters.EndTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntListEmpty(t *testing.T) {
|
||||||
|
repo, _ := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
tasks, result, err := repo.ListTasks(context.Background(), pagination.PaginationParams{Page: 1, PageSize: 10})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, tasks)
|
||||||
|
require.Equal(t, int64(0), result.Total)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntGetStatusAndProgress(t *testing.T) {
|
||||||
|
repo, client := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
task := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusPending,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: time.Now().UTC(), EndTime: time.Now().UTC().Add(time.Hour)},
|
||||||
|
CreatedBy: 3,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task))
|
||||||
|
|
||||||
|
status, err := repo.GetTaskStatus(context.Background(), task.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, service.UsageCleanupStatusPending, status)
|
||||||
|
|
||||||
|
_, err = repo.GetTaskStatus(context.Background(), task.ID+99)
|
||||||
|
require.ErrorIs(t, err, sql.ErrNoRows)
|
||||||
|
|
||||||
|
require.NoError(t, repo.UpdateTaskProgress(context.Background(), task.ID, 42))
|
||||||
|
loaded, err := client.UsageCleanupTask.Get(context.Background(), task.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(42), loaded.DeletedRows)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntCancelAndFinish(t *testing.T) {
|
||||||
|
repo, client := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
task := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusPending,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: time.Now().UTC(), EndTime: time.Now().UTC().Add(time.Hour)},
|
||||||
|
CreatedBy: 5,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task))
|
||||||
|
|
||||||
|
ok, err := repo.CancelTask(context.Background(), task.ID, 7)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
loaded, err := client.UsageCleanupTask.Get(context.Background(), task.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, service.UsageCleanupStatusCanceled, loaded.Status)
|
||||||
|
require.NotNil(t, loaded.CanceledBy)
|
||||||
|
require.NotNil(t, loaded.CanceledAt)
|
||||||
|
require.NotNil(t, loaded.FinishedAt)
|
||||||
|
|
||||||
|
loaded.Status = service.UsageCleanupStatusSucceeded
|
||||||
|
_, err = client.UsageCleanupTask.Update().Where(dbusagecleanuptask.IDEQ(task.ID)).SetStatus(loaded.Status).Save(context.Background())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ok, err = repo.CancelTask(context.Background(), task.ID, 7)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntCancelError(t *testing.T) {
|
||||||
|
repo, client := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
task := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusPending,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: time.Now().UTC(), EndTime: time.Now().UTC().Add(time.Hour)},
|
||||||
|
CreatedBy: 5,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task))
|
||||||
|
|
||||||
|
require.NoError(t, client.Close())
|
||||||
|
_, err := repo.CancelTask(context.Background(), task.ID, 7)
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntMarkResults(t *testing.T) {
|
||||||
|
repo, client := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
task := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusRunning,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: time.Now().UTC(), EndTime: time.Now().UTC().Add(time.Hour)},
|
||||||
|
CreatedBy: 12,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task))
|
||||||
|
|
||||||
|
require.NoError(t, repo.MarkTaskSucceeded(context.Background(), task.ID, 6))
|
||||||
|
loaded, err := client.UsageCleanupTask.Get(context.Background(), task.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, service.UsageCleanupStatusSucceeded, loaded.Status)
|
||||||
|
require.Equal(t, int64(6), loaded.DeletedRows)
|
||||||
|
require.NotNil(t, loaded.FinishedAt)
|
||||||
|
|
||||||
|
task2 := &service.UsageCleanupTask{
|
||||||
|
Status: service.UsageCleanupStatusRunning,
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: time.Now().UTC(), EndTime: time.Now().UTC().Add(time.Hour)},
|
||||||
|
CreatedBy: 12,
|
||||||
|
}
|
||||||
|
require.NoError(t, repo.CreateTask(context.Background(), task2))
|
||||||
|
|
||||||
|
require.NoError(t, repo.MarkTaskFailed(context.Background(), task2.ID, 4, "boom"))
|
||||||
|
loaded2, err := client.UsageCleanupTask.Get(context.Background(), task2.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, service.UsageCleanupStatusFailed, loaded2.Status)
|
||||||
|
require.Equal(t, "boom", *loaded2.ErrorMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntInvalidStatus(t *testing.T) {
|
||||||
|
repo, _ := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
task := &service.UsageCleanupTask{
|
||||||
|
Status: "invalid",
|
||||||
|
Filters: service.UsageCleanupFilters{StartTime: time.Now().UTC(), EndTime: time.Now().UTC().Add(time.Hour)},
|
||||||
|
CreatedBy: 1,
|
||||||
|
}
|
||||||
|
require.Error(t, repo.CreateTask(context.Background(), task))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryEntListInvalidFilters(t *testing.T) {
|
||||||
|
repo, client := newUsageCleanupEntRepo(t)
|
||||||
|
|
||||||
|
now := time.Now().UTC()
|
||||||
|
driver, ok := client.Driver().(*entsql.Driver)
|
||||||
|
require.True(t, ok)
|
||||||
|
_, err := driver.DB().ExecContext(
|
||||||
|
context.Background(),
|
||||||
|
`INSERT INTO usage_cleanup_tasks (status, filters, created_by, deleted_rows, created_at, updated_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)`,
|
||||||
|
service.UsageCleanupStatusPending,
|
||||||
|
[]byte("invalid-json"),
|
||||||
|
int64(1),
|
||||||
|
int64(0),
|
||||||
|
now,
|
||||||
|
now,
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, _, err = repo.ListTasks(context.Background(), pagination.PaginationParams{Page: 1, PageSize: 10})
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupTaskFromEntFull(t *testing.T) {
|
||||||
|
start := time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||||
|
end := start.Add(24 * time.Hour)
|
||||||
|
errMsg := "failed"
|
||||||
|
canceledBy := int64(2)
|
||||||
|
canceledAt := start.Add(time.Minute)
|
||||||
|
startedAt := start.Add(2 * time.Minute)
|
||||||
|
finishedAt := start.Add(3 * time.Minute)
|
||||||
|
filters := service.UsageCleanupFilters{StartTime: start, EndTime: end}
|
||||||
|
filtersJSON, err := json.Marshal(filters)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
task, err := usageCleanupTaskFromEnt(&dbent.UsageCleanupTask{
|
||||||
|
ID: 10,
|
||||||
|
Status: service.UsageCleanupStatusFailed,
|
||||||
|
Filters: filtersJSON,
|
||||||
|
CreatedBy: 11,
|
||||||
|
DeletedRows: 7,
|
||||||
|
ErrorMessage: &errMsg,
|
||||||
|
CanceledBy: &canceledBy,
|
||||||
|
CanceledAt: &canceledAt,
|
||||||
|
StartedAt: &startedAt,
|
||||||
|
FinishedAt: &finishedAt,
|
||||||
|
CreatedAt: start,
|
||||||
|
UpdatedAt: end,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, int64(10), task.ID)
|
||||||
|
require.Equal(t, service.UsageCleanupStatusFailed, task.Status)
|
||||||
|
require.NotNil(t, task.ErrorMsg)
|
||||||
|
require.NotNil(t, task.CanceledBy)
|
||||||
|
require.NotNil(t, task.CanceledAt)
|
||||||
|
require.NotNil(t, task.StartedAt)
|
||||||
|
require.NotNil(t, task.FinishedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupTaskFromEntInvalidFilters(t *testing.T) {
|
||||||
|
task, err := usageCleanupTaskFromEnt(&dbent.UsageCleanupTask{
|
||||||
|
Filters: json.RawMessage("invalid-json"),
|
||||||
|
})
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Empty(t, task)
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ func newSQLMock(t *testing.T) (*sql.DB, sqlmock.Sqlmock) {
|
|||||||
|
|
||||||
func TestNewUsageCleanupRepository(t *testing.T) {
|
func TestNewUsageCleanupRepository(t *testing.T) {
|
||||||
db, _ := newSQLMock(t)
|
db, _ := newSQLMock(t)
|
||||||
repo := NewUsageCleanupRepository(db)
|
repo := NewUsageCleanupRepository(nil, db)
|
||||||
require.NotNil(t, repo)
|
require.NotNil(t, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +146,21 @@ func TestUsageCleanupRepositoryListTasks(t *testing.T) {
|
|||||||
require.NoError(t, mock.ExpectationsWereMet())
|
require.NoError(t, mock.ExpectationsWereMet())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryListTasksQueryError(t *testing.T) {
|
||||||
|
db, mock := newSQLMock(t)
|
||||||
|
repo := &usageCleanupRepository{sql: db}
|
||||||
|
|
||||||
|
mock.ExpectQuery("SELECT COUNT\\(\\*\\) FROM usage_cleanup_tasks").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(int64(2)))
|
||||||
|
mock.ExpectQuery("SELECT id, status, filters, created_by, deleted_rows, error_message").
|
||||||
|
WithArgs(20, 0).
|
||||||
|
WillReturnError(sql.ErrConnDone)
|
||||||
|
|
||||||
|
_, _, err := repo.ListTasks(context.Background(), pagination.PaginationParams{Page: 1, PageSize: 20})
|
||||||
|
require.Error(t, err)
|
||||||
|
require.NoError(t, mock.ExpectationsWereMet())
|
||||||
|
}
|
||||||
|
|
||||||
func TestUsageCleanupRepositoryListTasksInvalidFilters(t *testing.T) {
|
func TestUsageCleanupRepositoryListTasksInvalidFilters(t *testing.T) {
|
||||||
db, mock := newSQLMock(t)
|
db, mock := newSQLMock(t)
|
||||||
repo := &usageCleanupRepository{sql: db}
|
repo := &usageCleanupRepository{sql: db}
|
||||||
@@ -320,6 +335,19 @@ func TestUsageCleanupRepositoryGetTaskStatus(t *testing.T) {
|
|||||||
require.NoError(t, mock.ExpectationsWereMet())
|
require.NoError(t, mock.ExpectationsWereMet())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryGetTaskStatusQueryError(t *testing.T) {
|
||||||
|
db, mock := newSQLMock(t)
|
||||||
|
repo := &usageCleanupRepository{sql: db}
|
||||||
|
|
||||||
|
mock.ExpectQuery("SELECT status FROM usage_cleanup_tasks").
|
||||||
|
WithArgs(int64(9)).
|
||||||
|
WillReturnError(sql.ErrConnDone)
|
||||||
|
|
||||||
|
_, err := repo.GetTaskStatus(context.Background(), 9)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.NoError(t, mock.ExpectationsWereMet())
|
||||||
|
}
|
||||||
|
|
||||||
func TestUsageCleanupRepositoryUpdateTaskProgress(t *testing.T) {
|
func TestUsageCleanupRepositoryUpdateTaskProgress(t *testing.T) {
|
||||||
db, mock := newSQLMock(t)
|
db, mock := newSQLMock(t)
|
||||||
repo := &usageCleanupRepository{sql: db}
|
repo := &usageCleanupRepository{sql: db}
|
||||||
@@ -347,6 +375,20 @@ func TestUsageCleanupRepositoryCancelTask(t *testing.T) {
|
|||||||
require.NoError(t, mock.ExpectationsWereMet())
|
require.NoError(t, mock.ExpectationsWereMet())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupRepositoryCancelTaskNoRows(t *testing.T) {
|
||||||
|
db, mock := newSQLMock(t)
|
||||||
|
repo := &usageCleanupRepository{sql: db}
|
||||||
|
|
||||||
|
mock.ExpectQuery("UPDATE usage_cleanup_tasks").
|
||||||
|
WithArgs(service.UsageCleanupStatusCanceled, int64(6), int64(9), service.UsageCleanupStatusPending, service.UsageCleanupStatusRunning).
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"id"}))
|
||||||
|
|
||||||
|
ok, err := repo.CancelTask(context.Background(), 6, 9)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, ok)
|
||||||
|
require.NoError(t, mock.ExpectationsWereMet())
|
||||||
|
}
|
||||||
|
|
||||||
func TestUsageCleanupRepositoryDeleteUsageLogsBatchMissingRange(t *testing.T) {
|
func TestUsageCleanupRepositoryDeleteUsageLogsBatchMissingRange(t *testing.T) {
|
||||||
db, _ := newSQLMock(t)
|
db, _ := newSQLMock(t)
|
||||||
repo := &usageCleanupRepository{sql: db}
|
repo := &usageCleanupRepository{sql: db}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ var (
|
|||||||
// ErrDashboardBackfillDisabled 当配置禁用回填时返回。
|
// ErrDashboardBackfillDisabled 当配置禁用回填时返回。
|
||||||
ErrDashboardBackfillDisabled = errors.New("仪表盘聚合回填已禁用")
|
ErrDashboardBackfillDisabled = errors.New("仪表盘聚合回填已禁用")
|
||||||
// ErrDashboardBackfillTooLarge 当回填跨度超过限制时返回。
|
// ErrDashboardBackfillTooLarge 当回填跨度超过限制时返回。
|
||||||
ErrDashboardBackfillTooLarge = errors.New("回填时间跨度过大")
|
ErrDashboardBackfillTooLarge = errors.New("回填时间跨度过大")
|
||||||
errDashboardAggregationRunning = errors.New("聚合作业正在运行")
|
errDashboardAggregationRunning = errors.New("聚合作业正在运行")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -151,20 +151,24 @@ func (s *UsageCleanupService) CreateTask(ctx context.Context, filters UsageClean
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *UsageCleanupService) runOnce() {
|
func (s *UsageCleanupService) runOnce() {
|
||||||
if !atomic.CompareAndSwapInt32(&s.running, 0, 1) {
|
svc := s
|
||||||
|
if svc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !atomic.CompareAndSwapInt32(&svc.running, 0, 1) {
|
||||||
log.Printf("[UsageCleanup] run_once skipped: already_running=true")
|
log.Printf("[UsageCleanup] run_once skipped: already_running=true")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer atomic.StoreInt32(&s.running, 0)
|
defer atomic.StoreInt32(&svc.running, 0)
|
||||||
|
|
||||||
parent := context.Background()
|
parent := context.Background()
|
||||||
if s != nil && s.workerCtx != nil {
|
if svc.workerCtx != nil {
|
||||||
parent = s.workerCtx
|
parent = svc.workerCtx
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithTimeout(parent, s.taskTimeout())
|
ctx, cancel := context.WithTimeout(parent, svc.taskTimeout())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
task, err := s.repo.ClaimNextPendingTask(ctx, int64(s.taskTimeout().Seconds()))
|
task, err := svc.repo.ClaimNextPendingTask(ctx, int64(svc.taskTimeout().Seconds()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[UsageCleanup] claim pending task failed: %v", err)
|
log.Printf("[UsageCleanup] claim pending task failed: %v", err)
|
||||||
return
|
return
|
||||||
@@ -175,7 +179,7 @@ func (s *UsageCleanupService) runOnce() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[UsageCleanup] task claimed: task=%d status=%s created_by=%d deleted_rows=%d %s", task.ID, task.Status, task.CreatedBy, task.DeletedRows, describeUsageCleanupFilters(task.Filters))
|
log.Printf("[UsageCleanup] task claimed: task=%d status=%s created_by=%d deleted_rows=%d %s", task.ID, task.Status, task.CreatedBy, task.DeletedRows, describeUsageCleanupFilters(task.Filters))
|
||||||
s.executeTask(ctx, task)
|
svc.executeTask(ctx, task)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UsageCleanupService) executeTask(ctx context.Context, task *UsageCleanupTask) {
|
func (s *UsageCleanupService) executeTask(ctx context.Context, task *UsageCleanupTask) {
|
||||||
|
|||||||
@@ -46,8 +46,45 @@ type cleanupRepoStub struct {
|
|||||||
markSucceeded []cleanupMarkCall
|
markSucceeded []cleanupMarkCall
|
||||||
markFailed []cleanupMarkCall
|
markFailed []cleanupMarkCall
|
||||||
statusByID map[int64]string
|
statusByID map[int64]string
|
||||||
|
statusErr error
|
||||||
progressCalls []cleanupMarkCall
|
progressCalls []cleanupMarkCall
|
||||||
|
updateErr error
|
||||||
cancelCalls []int64
|
cancelCalls []int64
|
||||||
|
cancelErr error
|
||||||
|
cancelResult *bool
|
||||||
|
markFailedErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
type dashboardRepoStub struct {
|
||||||
|
recomputeErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) AggregateRange(ctx context.Context, start, end time.Time) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) RecomputeRange(ctx context.Context, start, end time.Time) error {
|
||||||
|
return s.recomputeErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) GetAggregationWatermark(ctx context.Context) (time.Time, error) {
|
||||||
|
return time.Time{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) UpdateAggregationWatermark(ctx context.Context, aggregatedAt time.Time) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) CleanupAggregates(ctx context.Context, hourlyCutoff, dailyCutoff time.Time) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) CleanupUsageLogs(ctx context.Context, cutoff time.Time) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dashboardRepoStub) EnsureUsageLogsPartitions(ctx context.Context, now time.Time) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *cleanupRepoStub) CreateTask(ctx context.Context, task *UsageCleanupTask) error {
|
func (s *cleanupRepoStub) CreateTask(ctx context.Context, task *UsageCleanupTask) error {
|
||||||
@@ -100,6 +137,9 @@ func (s *cleanupRepoStub) ClaimNextPendingTask(ctx context.Context, staleRunning
|
|||||||
func (s *cleanupRepoStub) GetTaskStatus(ctx context.Context, taskID int64) (string, error) {
|
func (s *cleanupRepoStub) GetTaskStatus(ctx context.Context, taskID int64) (string, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
if s.statusErr != nil {
|
||||||
|
return "", s.statusErr
|
||||||
|
}
|
||||||
if s.statusByID == nil {
|
if s.statusByID == nil {
|
||||||
return "", sql.ErrNoRows
|
return "", sql.ErrNoRows
|
||||||
}
|
}
|
||||||
@@ -114,6 +154,9 @@ func (s *cleanupRepoStub) UpdateTaskProgress(ctx context.Context, taskID int64,
|
|||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.progressCalls = append(s.progressCalls, cleanupMarkCall{taskID: taskID, deletedRows: deletedRows})
|
s.progressCalls = append(s.progressCalls, cleanupMarkCall{taskID: taskID, deletedRows: deletedRows})
|
||||||
|
if s.updateErr != nil {
|
||||||
|
return s.updateErr
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +164,19 @@ func (s *cleanupRepoStub) CancelTask(ctx context.Context, taskID int64, canceled
|
|||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.cancelCalls = append(s.cancelCalls, taskID)
|
s.cancelCalls = append(s.cancelCalls, taskID)
|
||||||
|
if s.cancelErr != nil {
|
||||||
|
return false, s.cancelErr
|
||||||
|
}
|
||||||
|
if s.cancelResult != nil {
|
||||||
|
ok := *s.cancelResult
|
||||||
|
if ok {
|
||||||
|
if s.statusByID == nil {
|
||||||
|
s.statusByID = map[int64]string{}
|
||||||
|
}
|
||||||
|
s.statusByID[taskID] = UsageCleanupStatusCanceled
|
||||||
|
}
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
if s.statusByID == nil {
|
if s.statusByID == nil {
|
||||||
s.statusByID = map[int64]string{}
|
s.statusByID = map[int64]string{}
|
||||||
}
|
}
|
||||||
@@ -151,6 +207,9 @@ func (s *cleanupRepoStub) MarkTaskFailed(ctx context.Context, taskID int64, dele
|
|||||||
s.statusByID = map[int64]string{}
|
s.statusByID = map[int64]string{}
|
||||||
}
|
}
|
||||||
s.statusByID[taskID] = UsageCleanupStatusFailed
|
s.statusByID[taskID] = UsageCleanupStatusFailed
|
||||||
|
if s.markFailedErr != nil {
|
||||||
|
return s.markFailedErr
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,9 +325,11 @@ func TestUsageCleanupServiceCreateTaskRepoError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUsageCleanupServiceRunOnceSuccess(t *testing.T) {
|
func TestUsageCleanupServiceRunOnceSuccess(t *testing.T) {
|
||||||
|
start := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
end := start.Add(2 * time.Hour)
|
||||||
repo := &cleanupRepoStub{
|
repo := &cleanupRepoStub{
|
||||||
claimQueue: []*UsageCleanupTask{
|
claimQueue: []*UsageCleanupTask{
|
||||||
{ID: 5, Filters: UsageCleanupFilters{StartTime: time.Now(), EndTime: time.Now().Add(2 * time.Hour)}},
|
{ID: 5, Filters: UsageCleanupFilters{StartTime: start, EndTime: end}},
|
||||||
},
|
},
|
||||||
deleteQueue: []cleanupDeleteResponse{
|
deleteQueue: []cleanupDeleteResponse{
|
||||||
{deleted: 2},
|
{deleted: 2},
|
||||||
@@ -288,6 +349,9 @@ func TestUsageCleanupServiceRunOnceSuccess(t *testing.T) {
|
|||||||
require.Empty(t, repo.markFailed)
|
require.Empty(t, repo.markFailed)
|
||||||
require.Equal(t, int64(5), repo.markSucceeded[0].taskID)
|
require.Equal(t, int64(5), repo.markSucceeded[0].taskID)
|
||||||
require.Equal(t, int64(5), repo.markSucceeded[0].deletedRows)
|
require.Equal(t, int64(5), repo.markSucceeded[0].deletedRows)
|
||||||
|
require.Equal(t, 2, repo.deleteCalls[0].limit)
|
||||||
|
require.Equal(t, start, repo.deleteCalls[0].filters.StartTime)
|
||||||
|
require.Equal(t, end, repo.deleteCalls[0].filters.EndTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUsageCleanupServiceRunOnceClaimError(t *testing.T) {
|
func TestUsageCleanupServiceRunOnceClaimError(t *testing.T) {
|
||||||
@@ -336,6 +400,293 @@ func TestUsageCleanupServiceExecuteTaskFailed(t *testing.T) {
|
|||||||
require.Equal(t, 500, len(repo.markFailed[0].errMsg))
|
require.Equal(t, 500, len(repo.markFailed[0].errMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskProgressError(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
deleteQueue: []cleanupDeleteResponse{
|
||||||
|
{deleted: 2},
|
||||||
|
{deleted: 0},
|
||||||
|
},
|
||||||
|
updateErr: errors.New("update failed"),
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 8,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc.executeTask(context.Background(), task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Len(t, repo.markSucceeded, 1)
|
||||||
|
require.Empty(t, repo.markFailed)
|
||||||
|
require.Len(t, repo.progressCalls, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskDeleteCanceled(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
deleteQueue: []cleanupDeleteResponse{
|
||||||
|
{err: context.Canceled},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 12,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc.executeTask(context.Background(), task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Empty(t, repo.markSucceeded)
|
||||||
|
require.Empty(t, repo.markFailed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskContextCanceled(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 9,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
svc.executeTask(ctx, task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Empty(t, repo.markSucceeded)
|
||||||
|
require.Empty(t, repo.markFailed)
|
||||||
|
require.Empty(t, repo.deleteCalls)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskMarkFailedUpdateError(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
deleteQueue: []cleanupDeleteResponse{
|
||||||
|
{err: errors.New("boom")},
|
||||||
|
},
|
||||||
|
markFailedErr: errors.New("update failed"),
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 13,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc.executeTask(context.Background(), task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Len(t, repo.markFailed, 1)
|
||||||
|
require.Equal(t, int64(13), repo.markFailed[0].taskID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskDashboardRecomputeError(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
deleteQueue: []cleanupDeleteResponse{
|
||||||
|
{deleted: 0},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dashboard := NewDashboardAggregationService(&dashboardRepoStub{}, nil, &config.Config{
|
||||||
|
DashboardAgg: config.DashboardAggregationConfig{Enabled: false},
|
||||||
|
})
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, dashboard, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 14,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc.executeTask(context.Background(), task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Len(t, repo.markSucceeded, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskDashboardRecomputeSuccess(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
deleteQueue: []cleanupDeleteResponse{
|
||||||
|
{deleted: 0},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dashboard := NewDashboardAggregationService(&dashboardRepoStub{}, nil, &config.Config{
|
||||||
|
DashboardAgg: config.DashboardAggregationConfig{Enabled: true},
|
||||||
|
})
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, dashboard, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 15,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc.executeTask(context.Background(), task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Len(t, repo.markSucceeded, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceExecuteTaskCanceled(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
statusByID: map[int64]string{
|
||||||
|
3: UsageCleanupStatusCanceled,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true, BatchSize: 2}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
task := &UsageCleanupTask{
|
||||||
|
ID: 3,
|
||||||
|
Filters: UsageCleanupFilters{
|
||||||
|
StartTime: time.Now().UTC(),
|
||||||
|
EndTime: time.Now().UTC().Add(time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc.executeTask(context.Background(), task)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Empty(t, repo.deleteCalls)
|
||||||
|
require.Empty(t, repo.markSucceeded)
|
||||||
|
require.Empty(t, repo.markFailed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskSuccess(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
statusByID: map[int64]string{
|
||||||
|
5: UsageCleanupStatusPending,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 5, 9)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
repo.mu.Lock()
|
||||||
|
defer repo.mu.Unlock()
|
||||||
|
require.Equal(t, UsageCleanupStatusCanceled, repo.statusByID[5])
|
||||||
|
require.Len(t, repo.cancelCalls, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskDisabled(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: false}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 1, 2)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Equal(t, http.StatusServiceUnavailable, infraerrors.Code(err))
|
||||||
|
require.Equal(t, "USAGE_CLEANUP_DISABLED", infraerrors.Reason(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskNotFound(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 999, 1)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Equal(t, http.StatusNotFound, infraerrors.Code(err))
|
||||||
|
require.Equal(t, "USAGE_CLEANUP_TASK_NOT_FOUND", infraerrors.Reason(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskStatusError(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{statusErr: errors.New("status broken")}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 7, 1)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Contains(t, err.Error(), "status broken")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskConflict(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
statusByID: map[int64]string{
|
||||||
|
7: UsageCleanupStatusSucceeded,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 7, 1)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Equal(t, http.StatusConflict, infraerrors.Code(err))
|
||||||
|
require.Equal(t, "USAGE_CLEANUP_CANCEL_CONFLICT", infraerrors.Reason(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskRepoConflict(t *testing.T) {
|
||||||
|
shouldCancel := false
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
statusByID: map[int64]string{
|
||||||
|
7: UsageCleanupStatusPending,
|
||||||
|
},
|
||||||
|
cancelResult: &shouldCancel,
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 7, 1)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Equal(t, http.StatusConflict, infraerrors.Code(err))
|
||||||
|
require.Equal(t, "USAGE_CLEANUP_CANCEL_CONFLICT", infraerrors.Reason(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskRepoError(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
statusByID: map[int64]string{
|
||||||
|
7: UsageCleanupStatusPending,
|
||||||
|
},
|
||||||
|
cancelErr: errors.New("cancel failed"),
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 7, 1)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Contains(t, err.Error(), "cancel failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceCancelTaskInvalidCanceller(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{
|
||||||
|
statusByID: map[int64]string{
|
||||||
|
7: UsageCleanupStatusRunning,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cfg := &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, cfg)
|
||||||
|
|
||||||
|
err := svc.CancelTask(context.Background(), 7, 0)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Equal(t, "USAGE_CLEANUP_INVALID_CANCELLER", infraerrors.Reason(err))
|
||||||
|
}
|
||||||
|
|
||||||
func TestUsageCleanupServiceListTasks(t *testing.T) {
|
func TestUsageCleanupServiceListTasks(t *testing.T) {
|
||||||
repo := &cleanupRepoStub{
|
repo := &cleanupRepoStub{
|
||||||
listTasks: []UsageCleanupTask{{ID: 1}, {ID: 2}},
|
listTasks: []UsageCleanupTask{{ID: 1}, {ID: 2}},
|
||||||
@@ -418,3 +769,47 @@ func TestSanitizeUsageCleanupFiltersModelEmpty(t *testing.T) {
|
|||||||
require.Nil(t, filters.GroupID)
|
require.Nil(t, filters.GroupID)
|
||||||
require.Nil(t, filters.Model)
|
require.Nil(t, filters.Model)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDescribeUsageCleanupFiltersAllFields(t *testing.T) {
|
||||||
|
start := time.Date(2024, 2, 1, 10, 0, 0, 0, time.UTC)
|
||||||
|
end := start.Add(2 * time.Hour)
|
||||||
|
userID := int64(1)
|
||||||
|
apiKeyID := int64(2)
|
||||||
|
accountID := int64(3)
|
||||||
|
groupID := int64(4)
|
||||||
|
model := " gpt-4 "
|
||||||
|
stream := true
|
||||||
|
billingType := int8(2)
|
||||||
|
filters := UsageCleanupFilters{
|
||||||
|
StartTime: start,
|
||||||
|
EndTime: end,
|
||||||
|
UserID: &userID,
|
||||||
|
APIKeyID: &apiKeyID,
|
||||||
|
AccountID: &accountID,
|
||||||
|
GroupID: &groupID,
|
||||||
|
Model: &model,
|
||||||
|
Stream: &stream,
|
||||||
|
BillingType: &billingType,
|
||||||
|
}
|
||||||
|
|
||||||
|
desc := describeUsageCleanupFilters(filters)
|
||||||
|
require.Equal(t, "start=2024-02-01T10:00:00Z end=2024-02-01T12:00:00Z user_id=1 api_key_id=2 account_id=3 group_id=4 model=gpt-4 stream=true billing_type=2", desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceIsTaskCanceledNotFound(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}})
|
||||||
|
|
||||||
|
canceled, err := svc.isTaskCanceled(context.Background(), 9)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.False(t, canceled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUsageCleanupServiceIsTaskCanceledError(t *testing.T) {
|
||||||
|
repo := &cleanupRepoStub{statusErr: errors.New("status err")}
|
||||||
|
svc := NewUsageCleanupService(repo, nil, nil, &config.Config{UsageCleanup: config.UsageCleanupConfig{Enabled: true}})
|
||||||
|
|
||||||
|
_, err := svc.isTaskCanceled(context.Background(), 9)
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Contains(t, err.Error(), "status err")
|
||||||
|
}
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ const loadTasks = async () => {
|
|||||||
if (!props.show) return
|
if (!props.show) return
|
||||||
tasksLoading.value = true
|
tasksLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await adminUsageAPI.listCleanupTasks({ page: 1, page_size: 10 })
|
const res = await adminUsageAPI.listCleanupTasks({ page: 1, page_size: 5 })
|
||||||
tasks.value = res.items || []
|
tasks.value = res.items || []
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load cleanup tasks:', error)
|
console.error('Failed to load cleanup tasks:', error)
|
||||||
|
|||||||
Reference in New Issue
Block a user