Commit 5e060b22 authored by erio's avatar erio
Browse files

Merge remote-tracking branch 'upstream/main' into feat/channel-insights

# Conflicts:
#	backend/cmd/server/wire_gen.go
parents 6f04c25e 0a80ec80
...@@ -246,10 +246,10 @@ jobs: ...@@ -246,10 +246,10 @@ jobs:
if [ -n "$DOCKERHUB_USERNAME" ]; then if [ -n "$DOCKERHUB_USERNAME" ]; then
DOCKER_IMAGE="${DOCKERHUB_USERNAME}/sub2api" DOCKER_IMAGE="${DOCKERHUB_USERNAME}/sub2api"
MESSAGE+="# Docker Hub"$'\n' MESSAGE+="# Docker Hub"$'\n'
MESSAGE+="docker pull ${DOCKER_IMAGE}:${TAG_NAME}"$'\n' MESSAGE+="docker pull ${DOCKER_IMAGE}:${VERSION}"$'\n'
MESSAGE+="# GitHub Container Registry"$'\n' MESSAGE+="# GitHub Container Registry"$'\n'
fi fi
MESSAGE+="docker pull ${GHCR_IMAGE}:${TAG_NAME}"$'\n' MESSAGE+="docker pull ${GHCR_IMAGE}:${VERSION}"$'\n'
MESSAGE+="\`\`\`"$'\n'$'\n' MESSAGE+="\`\`\`"$'\n'$'\n'
MESSAGE+="🔗 *相关链接:*"$'\n' MESSAGE+="🔗 *相关链接:*"$'\n'
MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n' MESSAGE+="• [GitHub Release](https://github.com/${REPO}/releases/tag/${TAG_NAME})"$'\n'
......
...@@ -61,8 +61,9 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -61,8 +61,9 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
billingCache := repository.NewBillingCache(redisClient) billingCache := repository.NewBillingCache(redisClient)
userSubscriptionRepository := repository.NewUserSubscriptionRepository(client) userSubscriptionRepository := repository.NewUserSubscriptionRepository(client)
apiKeyRepository := repository.NewAPIKeyRepository(client, db) apiKeyRepository := repository.NewAPIKeyRepository(client, db)
billingCacheService := service.NewBillingCacheService(billingCache, userRepository, userSubscriptionRepository, apiKeyRepository, configConfig) userRPMCache := repository.NewUserRPMCache(redisClient)
userGroupRateRepository := repository.NewUserGroupRateRepository(db) userGroupRateRepository := repository.NewUserGroupRateRepository(db)
billingCacheService := service.ProvideBillingCacheService(billingCache, userRepository, userSubscriptionRepository, apiKeyRepository, userRPMCache, userGroupRateRepository, configConfig)
apiKeyCache := repository.NewAPIKeyCache(redisClient) apiKeyCache := repository.NewAPIKeyCache(redisClient)
apiKeyService := service.NewAPIKeyService(apiKeyRepository, userRepository, groupRepository, userSubscriptionRepository, userGroupRateRepository, apiKeyCache, configConfig) apiKeyService := service.NewAPIKeyService(apiKeyRepository, userRepository, groupRepository, userSubscriptionRepository, userGroupRateRepository, apiKeyCache, configConfig)
apiKeyAuthCacheInvalidator := service.ProvideAPIKeyAuthCacheInvalidator(apiKeyService) apiKeyAuthCacheInvalidator := service.ProvideAPIKeyAuthCacheInvalidator(apiKeyService)
...@@ -104,7 +105,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -104,7 +105,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
proxyExitInfoProber := repository.NewProxyExitInfoProber(configConfig) proxyExitInfoProber := repository.NewProxyExitInfoProber(configConfig)
proxyLatencyCache := repository.NewProxyLatencyCache(redisClient) proxyLatencyCache := repository.NewProxyLatencyCache(redisClient)
privacyClientFactory := providePrivacyClientFactory() privacyClientFactory := providePrivacyClientFactory()
adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService, userSubscriptionRepository, privacyClientFactory) adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, userRPMCache, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService, userSubscriptionRepository, privacyClientFactory)
concurrencyCache := repository.ProvideConcurrencyCache(redisClient, configConfig) concurrencyCache := repository.ProvideConcurrencyCache(redisClient, configConfig)
concurrencyService := service.ProvideConcurrencyService(concurrencyCache, accountRepository, configConfig) concurrencyService := service.ProvideConcurrencyService(concurrencyCache, accountRepository, configConfig)
adminUserHandler := admin.NewUserHandler(adminService, concurrencyService) adminUserHandler := admin.NewUserHandler(adminService, concurrencyService)
...@@ -124,9 +125,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -124,9 +125,10 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
geminiQuotaService := service.NewGeminiQuotaService(configConfig, settingRepository) geminiQuotaService := service.NewGeminiQuotaService(configConfig, settingRepository)
tempUnschedCache := repository.NewTempUnschedCache(redisClient) tempUnschedCache := repository.NewTempUnschedCache(redisClient)
timeoutCounterCache := repository.NewTimeoutCounterCache(redisClient) timeoutCounterCache := repository.NewTimeoutCounterCache(redisClient)
openAI403CounterCache := repository.NewOpenAI403CounterCache(redisClient)
geminiTokenCache := repository.NewGeminiTokenCache(redisClient) geminiTokenCache := repository.NewGeminiTokenCache(redisClient)
compositeTokenCacheInvalidator := service.NewCompositeTokenCacheInvalidator(geminiTokenCache) compositeTokenCacheInvalidator := service.NewCompositeTokenCacheInvalidator(geminiTokenCache)
rateLimitService := service.ProvideRateLimitService(accountRepository, usageLogRepository, configConfig, geminiQuotaService, tempUnschedCache, timeoutCounterCache, settingService, compositeTokenCacheInvalidator) rateLimitService := service.ProvideRateLimitService(accountRepository, usageLogRepository, configConfig, geminiQuotaService, tempUnschedCache, timeoutCounterCache, openAI403CounterCache, settingService, compositeTokenCacheInvalidator)
httpUpstream := repository.NewHTTPUpstream(configConfig) httpUpstream := repository.NewHTTPUpstream(configConfig)
claudeUsageFetcher := repository.NewClaudeUsageFetcher(httpUpstream) claudeUsageFetcher := repository.NewClaudeUsageFetcher(httpUpstream)
antigravityQuotaFetcher := service.NewAntigravityQuotaFetcher(proxyRepository) antigravityQuotaFetcher := service.NewAntigravityQuotaFetcher(proxyRepository)
...@@ -136,7 +138,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -136,7 +138,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
tlsFingerprintProfileCache := repository.NewTLSFingerprintProfileCache(redisClient) tlsFingerprintProfileCache := repository.NewTLSFingerprintProfileCache(redisClient)
tlsFingerprintProfileService := service.NewTLSFingerprintProfileService(tlsFingerprintProfileRepository, tlsFingerprintProfileCache) tlsFingerprintProfileService := service.NewTLSFingerprintProfileService(tlsFingerprintProfileRepository, tlsFingerprintProfileCache)
accountUsageService := service.NewAccountUsageService(accountRepository, usageLogRepository, claudeUsageFetcher, geminiQuotaService, antigravityQuotaFetcher, usageCache, identityCache, tlsFingerprintProfileService) accountUsageService := service.NewAccountUsageService(accountRepository, usageLogRepository, claudeUsageFetcher, geminiQuotaService, antigravityQuotaFetcher, usageCache, identityCache, tlsFingerprintProfileService)
oAuthRefreshAPI := service.NewOAuthRefreshAPI(accountRepository, geminiTokenCache) oAuthRefreshAPI := service.ProvideOAuthRefreshAPI(accountRepository, geminiTokenCache)
geminiTokenProvider := service.ProvideGeminiTokenProvider(accountRepository, geminiTokenCache, geminiOAuthService, oAuthRefreshAPI) geminiTokenProvider := service.ProvideGeminiTokenProvider(accountRepository, geminiTokenCache, geminiOAuthService, oAuthRefreshAPI)
gatewayCache := repository.NewGatewayCache(redisClient) gatewayCache := repository.NewGatewayCache(redisClient)
schedulerOutboxRepository := repository.NewSchedulerOutboxRepository(db) schedulerOutboxRepository := repository.NewSchedulerOutboxRepository(db)
...@@ -183,6 +185,15 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -183,6 +185,15 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
geminiMessagesCompatService := service.NewGeminiMessagesCompatService(accountRepository, groupRepository, gatewayCache, schedulerSnapshotService, geminiTokenProvider, rateLimitService, httpUpstream, antigravityGatewayService, configConfig) geminiMessagesCompatService := service.NewGeminiMessagesCompatService(accountRepository, groupRepository, gatewayCache, schedulerSnapshotService, geminiTokenProvider, rateLimitService, httpUpstream, antigravityGatewayService, configConfig)
opsSystemLogSink := service.ProvideOpsSystemLogSink(opsRepository) opsSystemLogSink := service.ProvideOpsSystemLogSink(opsRepository)
opsService := service.NewOpsService(opsRepository, settingRepository, configConfig, accountRepository, userRepository, concurrencyService, gatewayService, openAIGatewayService, geminiMessagesCompatService, antigravityGatewayService, opsSystemLogSink) opsService := service.NewOpsService(opsRepository, settingRepository, configConfig, accountRepository, userRepository, concurrencyService, gatewayService, openAIGatewayService, geminiMessagesCompatService, antigravityGatewayService, opsSystemLogSink)
encryptionKey, err := payment.ProvideEncryptionKey(configConfig)
if err != nil {
return nil, err
}
paymentConfigService := service.ProvidePaymentConfigService(client, settingRepository, encryptionKey)
registry := payment.ProvideRegistry()
defaultLoadBalancer := payment.ProvideDefaultLoadBalancer(client, encryptionKey)
paymentService := service.NewPaymentService(client, registry, defaultLoadBalancer, redeemService, subscriptionService, paymentConfigService, userRepository, groupRepository)
settingHandler := admin.NewSettingHandler(settingService, emailService, turnstileService, opsService, paymentConfigService, paymentService)
opsHandler := admin.NewOpsHandler(opsService) opsHandler := admin.NewOpsHandler(opsService)
updateCache := repository.NewUpdateCache(redisClient) updateCache := repository.NewUpdateCache(redisClient)
gitHubReleaseClient := repository.ProvideGitHubReleaseClient(configConfig) gitHubReleaseClient := repository.ProvideGitHubReleaseClient(configConfig)
...@@ -222,16 +233,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -222,16 +233,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
channelMonitorHandler := admin.NewChannelMonitorHandler(channelMonitorService) channelMonitorHandler := admin.NewChannelMonitorHandler(channelMonitorService)
channelMonitorUserHandler := handler.NewChannelMonitorUserHandler(channelMonitorService, settingService) channelMonitorUserHandler := handler.NewChannelMonitorUserHandler(channelMonitorService, settingService)
channelMonitorRunner := service.ProvideChannelMonitorRunner(channelMonitorService, settingService) channelMonitorRunner := service.ProvideChannelMonitorRunner(channelMonitorService, settingService)
registry := payment.ProvideRegistry()
encryptionKey, err := payment.ProvideEncryptionKey(configConfig)
if err != nil {
return nil, err
}
defaultLoadBalancer := payment.ProvideDefaultLoadBalancer(client, encryptionKey)
paymentConfigService := service.ProvidePaymentConfigService(client, settingRepository, encryptionKey)
paymentService := service.NewPaymentService(client, registry, defaultLoadBalancer, redeemService, subscriptionService, paymentConfigService, userRepository, groupRepository)
settingHandler := admin.NewSettingHandler(settingService, emailService, turnstileService, opsService, paymentConfigService, paymentService)
paymentOrderExpiryService := service.ProvidePaymentOrderExpiryService(paymentService)
paymentHandler := admin.NewPaymentHandler(paymentService, paymentConfigService) paymentHandler := admin.NewPaymentHandler(paymentService, paymentConfigService)
availableChannelUserHandler := handler.NewAvailableChannelHandler(channelService, apiKeyService, settingService) availableChannelUserHandler := handler.NewAvailableChannelHandler(channelService, apiKeyService, settingService)
adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, backupHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, tlsFingerprintProfileHandler, adminAPIKeyHandler, scheduledTestHandler, channelHandler, channelMonitorHandler, channelMonitorRequestTemplateHandler, paymentHandler) adminHandlers := handler.ProvideAdminHandlers(dashboardHandler, adminUserHandler, groupHandler, accountHandler, adminAnnouncementHandler, dataManagementHandler, backupHandler, oAuthHandler, openAIOAuthHandler, geminiOAuthHandler, antigravityOAuthHandler, proxyHandler, adminRedeemHandler, promoHandler, settingHandler, opsHandler, systemHandler, adminSubscriptionHandler, adminUsageHandler, userAttributeHandler, errorPassthroughHandler, tlsFingerprintProfileHandler, adminAPIKeyHandler, scheduledTestHandler, channelHandler, channelMonitorHandler, channelMonitorRequestTemplateHandler, paymentHandler)
...@@ -261,6 +262,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { ...@@ -261,6 +262,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
accountExpiryService := service.ProvideAccountExpiryService(accountRepository) accountExpiryService := service.ProvideAccountExpiryService(accountRepository)
subscriptionExpiryService := service.ProvideSubscriptionExpiryService(userSubscriptionRepository) subscriptionExpiryService := service.ProvideSubscriptionExpiryService(userSubscriptionRepository)
scheduledTestRunnerService := service.ProvideScheduledTestRunnerService(scheduledTestPlanRepository, scheduledTestService, accountTestService, rateLimitService, configConfig) scheduledTestRunnerService := service.ProvideScheduledTestRunnerService(scheduledTestPlanRepository, scheduledTestService, accountTestService, rateLimitService, configConfig)
paymentOrderExpiryService := service.ProvidePaymentOrderExpiryService(paymentService)
v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, schedulerSnapshotService, tokenRefreshService, accountExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, openAIGatewayService, scheduledTestRunnerService, backupService, paymentOrderExpiryService, channelMonitorRunner) v := provideCleanup(client, redisClient, opsMetricsCollector, opsAggregationService, opsAlertEvaluatorService, opsCleanupService, opsScheduledReportService, opsSystemLogSink, schedulerSnapshotService, tokenRefreshService, accountExpiryService, subscriptionExpiryService, usageCleanupService, idempotencyCleanupService, pricingService, emailQueueService, billingCacheService, usageRecordWorkerPool, subscriptionService, oAuthService, openAIOAuthService, geminiOAuthService, antigravityOAuthService, openAIGatewayService, scheduledTestRunnerService, backupService, paymentOrderExpiryService, channelMonitorRunner)
application := &Application{ application := &Application{
Server: httpServer, Server: httpServer,
......
...@@ -43,7 +43,7 @@ func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) { ...@@ -43,7 +43,7 @@ func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) {
subscriptionExpirySvc := service.NewSubscriptionExpiryService(nil, time.Second) subscriptionExpirySvc := service.NewSubscriptionExpiryService(nil, time.Second)
pricingSvc := service.NewPricingService(cfg, nil) pricingSvc := service.NewPricingService(cfg, nil)
emailQueueSvc := service.NewEmailQueueService(nil, 1) emailQueueSvc := service.NewEmailQueueService(nil, 1)
billingCacheSvc := service.NewBillingCacheService(nil, nil, nil, nil, cfg) billingCacheSvc := service.NewBillingCacheService(nil, nil, nil, nil, nil, nil, cfg)
idempotencyCleanupSvc := service.NewIdempotencyCleanupService(nil, cfg) idempotencyCleanupSvc := service.NewIdempotencyCleanupService(nil, cfg)
schedulerSnapshotSvc := service.NewSchedulerSnapshotService(nil, nil, nil, nil, cfg) schedulerSnapshotSvc := service.NewSchedulerSnapshotService(nil, nil, nil, nil, cfg)
opsSystemLogSinkSvc := service.NewOpsSystemLogSink(nil) opsSystemLogSinkSvc := service.NewOpsSystemLogSink(nil)
......
...@@ -79,6 +79,8 @@ type Group struct { ...@@ -79,6 +79,8 @@ type Group struct {
DefaultMappedModel string `json:"default_mapped_model,omitempty"` DefaultMappedModel string `json:"default_mapped_model,omitempty"`
// OpenAI Messages 调度模型配置:按 Claude 系列/精确模型映射到目标 GPT 模型 // OpenAI Messages 调度模型配置:按 Claude 系列/精确模型映射到目标 GPT 模型
MessagesDispatchModelConfig domain.OpenAIMessagesDispatchModelConfig `json:"messages_dispatch_model_config,omitempty"` MessagesDispatchModelConfig domain.OpenAIMessagesDispatchModelConfig `json:"messages_dispatch_model_config,omitempty"`
// 分组 RPM 上限,0 表示不限制;设置后接管该分组用户的限流
RpmLimit int `json:"rpm_limit,omitempty"`
// Edges holds the relations/edges for other nodes in the graph. // Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the GroupQuery when eager-loading is set. // The values are being populated by the GroupQuery when eager-loading is set.
Edges GroupEdges `json:"edges"` Edges GroupEdges `json:"edges"`
...@@ -191,7 +193,7 @@ func (*Group) scanValues(columns []string) ([]any, error) { ...@@ -191,7 +193,7 @@ func (*Group) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool) values[i] = new(sql.NullBool)
case group.FieldRateMultiplier, group.FieldDailyLimitUsd, group.FieldWeeklyLimitUsd, group.FieldMonthlyLimitUsd, group.FieldImagePrice1k, group.FieldImagePrice2k, group.FieldImagePrice4k: case group.FieldRateMultiplier, group.FieldDailyLimitUsd, group.FieldWeeklyLimitUsd, group.FieldMonthlyLimitUsd, group.FieldImagePrice1k, group.FieldImagePrice2k, group.FieldImagePrice4k:
values[i] = new(sql.NullFloat64) values[i] = new(sql.NullFloat64)
case group.FieldID, group.FieldDefaultValidityDays, group.FieldFallbackGroupID, group.FieldFallbackGroupIDOnInvalidRequest, group.FieldSortOrder: case group.FieldID, group.FieldDefaultValidityDays, group.FieldFallbackGroupID, group.FieldFallbackGroupIDOnInvalidRequest, group.FieldSortOrder, group.FieldRpmLimit:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case group.FieldName, group.FieldDescription, group.FieldStatus, group.FieldPlatform, group.FieldSubscriptionType, group.FieldDefaultMappedModel: case group.FieldName, group.FieldDescription, group.FieldStatus, group.FieldPlatform, group.FieldSubscriptionType, group.FieldDefaultMappedModel:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
...@@ -414,6 +416,12 @@ func (_m *Group) assignValues(columns []string, values []any) error { ...@@ -414,6 +416,12 @@ func (_m *Group) assignValues(columns []string, values []any) error {
return fmt.Errorf("unmarshal field messages_dispatch_model_config: %w", err) return fmt.Errorf("unmarshal field messages_dispatch_model_config: %w", err)
} }
} }
case group.FieldRpmLimit:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field rpm_limit", values[i])
} else if value.Valid {
_m.RpmLimit = int(value.Int64)
}
default: default:
_m.selectValues.Set(columns[i], values[i]) _m.selectValues.Set(columns[i], values[i])
} }
...@@ -599,6 +607,9 @@ func (_m *Group) String() string { ...@@ -599,6 +607,9 @@ func (_m *Group) String() string {
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("messages_dispatch_model_config=") builder.WriteString("messages_dispatch_model_config=")
builder.WriteString(fmt.Sprintf("%v", _m.MessagesDispatchModelConfig)) builder.WriteString(fmt.Sprintf("%v", _m.MessagesDispatchModelConfig))
builder.WriteString(", ")
builder.WriteString("rpm_limit=")
builder.WriteString(fmt.Sprintf("%v", _m.RpmLimit))
builder.WriteByte(')') builder.WriteByte(')')
return builder.String() return builder.String()
} }
......
...@@ -76,6 +76,8 @@ const ( ...@@ -76,6 +76,8 @@ const (
FieldDefaultMappedModel = "default_mapped_model" FieldDefaultMappedModel = "default_mapped_model"
// FieldMessagesDispatchModelConfig holds the string denoting the messages_dispatch_model_config field in the database. // FieldMessagesDispatchModelConfig holds the string denoting the messages_dispatch_model_config field in the database.
FieldMessagesDispatchModelConfig = "messages_dispatch_model_config" FieldMessagesDispatchModelConfig = "messages_dispatch_model_config"
// FieldRpmLimit holds the string denoting the rpm_limit field in the database.
FieldRpmLimit = "rpm_limit"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations. // EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys = "api_keys" EdgeAPIKeys = "api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations. // EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...@@ -181,6 +183,7 @@ var Columns = []string{ ...@@ -181,6 +183,7 @@ var Columns = []string{
FieldRequirePrivacySet, FieldRequirePrivacySet,
FieldDefaultMappedModel, FieldDefaultMappedModel,
FieldMessagesDispatchModelConfig, FieldMessagesDispatchModelConfig,
FieldRpmLimit,
} }
var ( var (
...@@ -258,6 +261,8 @@ var ( ...@@ -258,6 +261,8 @@ var (
DefaultMappedModelValidator func(string) error DefaultMappedModelValidator func(string) error
// DefaultMessagesDispatchModelConfig holds the default value on creation for the "messages_dispatch_model_config" field. // DefaultMessagesDispatchModelConfig holds the default value on creation for the "messages_dispatch_model_config" field.
DefaultMessagesDispatchModelConfig domain.OpenAIMessagesDispatchModelConfig DefaultMessagesDispatchModelConfig domain.OpenAIMessagesDispatchModelConfig
// DefaultRpmLimit holds the default value on creation for the "rpm_limit" field.
DefaultRpmLimit int
) )
// OrderOption defines the ordering options for the Group queries. // OrderOption defines the ordering options for the Group queries.
...@@ -403,6 +408,11 @@ func ByDefaultMappedModel(opts ...sql.OrderTermOption) OrderOption { ...@@ -403,6 +408,11 @@ func ByDefaultMappedModel(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDefaultMappedModel, opts...).ToFunc() return sql.OrderByField(FieldDefaultMappedModel, opts...).ToFunc()
} }
// ByRpmLimit orders the results by the rpm_limit field.
func ByRpmLimit(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRpmLimit, opts...).ToFunc()
}
// ByAPIKeysCount orders the results by api_keys count. // ByAPIKeysCount orders the results by api_keys count.
func ByAPIKeysCount(opts ...sql.OrderTermOption) OrderOption { func ByAPIKeysCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) { return func(s *sql.Selector) {
......
...@@ -190,6 +190,11 @@ func DefaultMappedModel(v string) predicate.Group { ...@@ -190,6 +190,11 @@ func DefaultMappedModel(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldDefaultMappedModel, v)) return predicate.Group(sql.FieldEQ(FieldDefaultMappedModel, v))
} }
// RpmLimit applies equality check predicate on the "rpm_limit" field. It's identical to RpmLimitEQ.
func RpmLimit(v int) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldRpmLimit, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Group { func CreatedAtEQ(v time.Time) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldCreatedAt, v)) return predicate.Group(sql.FieldEQ(FieldCreatedAt, v))
...@@ -1320,6 +1325,46 @@ func DefaultMappedModelContainsFold(v string) predicate.Group { ...@@ -1320,6 +1325,46 @@ func DefaultMappedModelContainsFold(v string) predicate.Group {
return predicate.Group(sql.FieldContainsFold(FieldDefaultMappedModel, v)) return predicate.Group(sql.FieldContainsFold(FieldDefaultMappedModel, v))
} }
// RpmLimitEQ applies the EQ predicate on the "rpm_limit" field.
func RpmLimitEQ(v int) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldRpmLimit, v))
}
// RpmLimitNEQ applies the NEQ predicate on the "rpm_limit" field.
func RpmLimitNEQ(v int) predicate.Group {
return predicate.Group(sql.FieldNEQ(FieldRpmLimit, v))
}
// RpmLimitIn applies the In predicate on the "rpm_limit" field.
func RpmLimitIn(vs ...int) predicate.Group {
return predicate.Group(sql.FieldIn(FieldRpmLimit, vs...))
}
// RpmLimitNotIn applies the NotIn predicate on the "rpm_limit" field.
func RpmLimitNotIn(vs ...int) predicate.Group {
return predicate.Group(sql.FieldNotIn(FieldRpmLimit, vs...))
}
// RpmLimitGT applies the GT predicate on the "rpm_limit" field.
func RpmLimitGT(v int) predicate.Group {
return predicate.Group(sql.FieldGT(FieldRpmLimit, v))
}
// RpmLimitGTE applies the GTE predicate on the "rpm_limit" field.
func RpmLimitGTE(v int) predicate.Group {
return predicate.Group(sql.FieldGTE(FieldRpmLimit, v))
}
// RpmLimitLT applies the LT predicate on the "rpm_limit" field.
func RpmLimitLT(v int) predicate.Group {
return predicate.Group(sql.FieldLT(FieldRpmLimit, v))
}
// RpmLimitLTE applies the LTE predicate on the "rpm_limit" field.
func RpmLimitLTE(v int) predicate.Group {
return predicate.Group(sql.FieldLTE(FieldRpmLimit, v))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge. // HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func HasAPIKeys() predicate.Group { func HasAPIKeys() predicate.Group {
return predicate.Group(func(s *sql.Selector) { return predicate.Group(func(s *sql.Selector) {
......
...@@ -425,6 +425,20 @@ func (_c *GroupCreate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMe ...@@ -425,6 +425,20 @@ func (_c *GroupCreate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMe
return _c return _c
} }
// SetRpmLimit sets the "rpm_limit" field.
func (_c *GroupCreate) SetRpmLimit(v int) *GroupCreate {
_c.mutation.SetRpmLimit(v)
return _c
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func (_c *GroupCreate) SetNillableRpmLimit(v *int) *GroupCreate {
if v != nil {
_c.SetRpmLimit(*v)
}
return _c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_c *GroupCreate) AddAPIKeyIDs(ids ...int64) *GroupCreate { func (_c *GroupCreate) AddAPIKeyIDs(ids ...int64) *GroupCreate {
_c.mutation.AddAPIKeyIDs(ids...) _c.mutation.AddAPIKeyIDs(ids...)
...@@ -630,6 +644,10 @@ func (_c *GroupCreate) defaults() error { ...@@ -630,6 +644,10 @@ func (_c *GroupCreate) defaults() error {
v := group.DefaultMessagesDispatchModelConfig v := group.DefaultMessagesDispatchModelConfig
_c.mutation.SetMessagesDispatchModelConfig(v) _c.mutation.SetMessagesDispatchModelConfig(v)
} }
if _, ok := _c.mutation.RpmLimit(); !ok {
v := group.DefaultRpmLimit
_c.mutation.SetRpmLimit(v)
}
return nil return nil
} }
...@@ -717,6 +735,9 @@ func (_c *GroupCreate) check() error { ...@@ -717,6 +735,9 @@ func (_c *GroupCreate) check() error {
if _, ok := _c.mutation.MessagesDispatchModelConfig(); !ok { if _, ok := _c.mutation.MessagesDispatchModelConfig(); !ok {
return &ValidationError{Name: "messages_dispatch_model_config", err: errors.New(`ent: missing required field "Group.messages_dispatch_model_config"`)} return &ValidationError{Name: "messages_dispatch_model_config", err: errors.New(`ent: missing required field "Group.messages_dispatch_model_config"`)}
} }
if _, ok := _c.mutation.RpmLimit(); !ok {
return &ValidationError{Name: "rpm_limit", err: errors.New(`ent: missing required field "Group.rpm_limit"`)}
}
return nil return nil
} }
...@@ -864,6 +885,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { ...@@ -864,6 +885,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value) _spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value)
_node.MessagesDispatchModelConfig = value _node.MessagesDispatchModelConfig = value
} }
if value, ok := _c.mutation.RpmLimit(); ok {
_spec.SetField(group.FieldRpmLimit, field.TypeInt, value)
_node.RpmLimit = value
}
if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 { if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M, Rel: sqlgraph.O2M,
...@@ -1500,6 +1525,24 @@ func (u *GroupUpsert) UpdateMessagesDispatchModelConfig() *GroupUpsert { ...@@ -1500,6 +1525,24 @@ func (u *GroupUpsert) UpdateMessagesDispatchModelConfig() *GroupUpsert {
return u return u
} }
// SetRpmLimit sets the "rpm_limit" field.
func (u *GroupUpsert) SetRpmLimit(v int) *GroupUpsert {
u.Set(group.FieldRpmLimit, v)
return u
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func (u *GroupUpsert) UpdateRpmLimit() *GroupUpsert {
u.SetExcluded(group.FieldRpmLimit)
return u
}
// AddRpmLimit adds v to the "rpm_limit" field.
func (u *GroupUpsert) AddRpmLimit(v int) *GroupUpsert {
u.Add(group.FieldRpmLimit, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create. // UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using: // Using this option is equivalent to using:
// //
...@@ -2105,6 +2148,27 @@ func (u *GroupUpsertOne) UpdateMessagesDispatchModelConfig() *GroupUpsertOne { ...@@ -2105,6 +2148,27 @@ func (u *GroupUpsertOne) UpdateMessagesDispatchModelConfig() *GroupUpsertOne {
}) })
} }
// SetRpmLimit sets the "rpm_limit" field.
func (u *GroupUpsertOne) SetRpmLimit(v int) *GroupUpsertOne {
return u.Update(func(s *GroupUpsert) {
s.SetRpmLimit(v)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func (u *GroupUpsertOne) AddRpmLimit(v int) *GroupUpsertOne {
return u.Update(func(s *GroupUpsert) {
s.AddRpmLimit(v)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func (u *GroupUpsertOne) UpdateRpmLimit() *GroupUpsertOne {
return u.Update(func(s *GroupUpsert) {
s.UpdateRpmLimit()
})
}
// Exec executes the query. // Exec executes the query.
func (u *GroupUpsertOne) Exec(ctx context.Context) error { func (u *GroupUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 { if len(u.create.conflict) == 0 {
...@@ -2876,6 +2940,27 @@ func (u *GroupUpsertBulk) UpdateMessagesDispatchModelConfig() *GroupUpsertBulk { ...@@ -2876,6 +2940,27 @@ func (u *GroupUpsertBulk) UpdateMessagesDispatchModelConfig() *GroupUpsertBulk {
}) })
} }
// SetRpmLimit sets the "rpm_limit" field.
func (u *GroupUpsertBulk) SetRpmLimit(v int) *GroupUpsertBulk {
return u.Update(func(s *GroupUpsert) {
s.SetRpmLimit(v)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func (u *GroupUpsertBulk) AddRpmLimit(v int) *GroupUpsertBulk {
return u.Update(func(s *GroupUpsert) {
s.AddRpmLimit(v)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func (u *GroupUpsertBulk) UpdateRpmLimit() *GroupUpsertBulk {
return u.Update(func(s *GroupUpsert) {
s.UpdateRpmLimit()
})
}
// Exec executes the query. // Exec executes the query.
func (u *GroupUpsertBulk) Exec(ctx context.Context) error { func (u *GroupUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil { if u.create.err != nil {
......
...@@ -567,6 +567,27 @@ func (_u *GroupUpdate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMe ...@@ -567,6 +567,27 @@ func (_u *GroupUpdate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMe
return _u return _u
} }
// SetRpmLimit sets the "rpm_limit" field.
func (_u *GroupUpdate) SetRpmLimit(v int) *GroupUpdate {
_u.mutation.ResetRpmLimit()
_u.mutation.SetRpmLimit(v)
return _u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableRpmLimit(v *int) *GroupUpdate {
if v != nil {
_u.SetRpmLimit(*v)
}
return _u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func (_u *GroupUpdate) AddRpmLimit(v int) *GroupUpdate {
_u.mutation.AddRpmLimit(v)
return _u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *GroupUpdate) AddAPIKeyIDs(ids ...int64) *GroupUpdate { func (_u *GroupUpdate) AddAPIKeyIDs(ids ...int64) *GroupUpdate {
_u.mutation.AddAPIKeyIDs(ids...) _u.mutation.AddAPIKeyIDs(ids...)
...@@ -1030,6 +1051,12 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { ...@@ -1030,6 +1051,12 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if value, ok := _u.mutation.MessagesDispatchModelConfig(); ok { if value, ok := _u.mutation.MessagesDispatchModelConfig(); ok {
_spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value) _spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value)
} }
if value, ok := _u.mutation.RpmLimit(); ok {
_spec.SetField(group.FieldRpmLimit, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRpmLimit(); ok {
_spec.AddField(group.FieldRpmLimit, field.TypeInt, value)
}
if _u.mutation.APIKeysCleared() { if _u.mutation.APIKeysCleared() {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M, Rel: sqlgraph.O2M,
...@@ -1875,6 +1902,27 @@ func (_u *GroupUpdateOne) SetNillableMessagesDispatchModelConfig(v *domain.OpenA ...@@ -1875,6 +1902,27 @@ func (_u *GroupUpdateOne) SetNillableMessagesDispatchModelConfig(v *domain.OpenA
return _u return _u
} }
// SetRpmLimit sets the "rpm_limit" field.
func (_u *GroupUpdateOne) SetRpmLimit(v int) *GroupUpdateOne {
_u.mutation.ResetRpmLimit()
_u.mutation.SetRpmLimit(v)
return _u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableRpmLimit(v *int) *GroupUpdateOne {
if v != nil {
_u.SetRpmLimit(*v)
}
return _u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func (_u *GroupUpdateOne) AddRpmLimit(v int) *GroupUpdateOne {
_u.mutation.AddRpmLimit(v)
return _u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *GroupUpdateOne) AddAPIKeyIDs(ids ...int64) *GroupUpdateOne { func (_u *GroupUpdateOne) AddAPIKeyIDs(ids ...int64) *GroupUpdateOne {
_u.mutation.AddAPIKeyIDs(ids...) _u.mutation.AddAPIKeyIDs(ids...)
...@@ -2368,6 +2416,12 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) ...@@ -2368,6 +2416,12 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if value, ok := _u.mutation.MessagesDispatchModelConfig(); ok { if value, ok := _u.mutation.MessagesDispatchModelConfig(); ok {
_spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value) _spec.SetField(group.FieldMessagesDispatchModelConfig, field.TypeJSON, value)
} }
if value, ok := _u.mutation.RpmLimit(); ok {
_spec.SetField(group.FieldRpmLimit, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRpmLimit(); ok {
_spec.AddField(group.FieldRpmLimit, field.TypeInt, value)
}
if _u.mutation.APIKeysCleared() { if _u.mutation.APIKeysCleared() {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M, Rel: sqlgraph.O2M,
......
...@@ -654,6 +654,7 @@ var ( ...@@ -654,6 +654,7 @@ var (
{Name: "require_privacy_set", Type: field.TypeBool, Default: false}, {Name: "require_privacy_set", Type: field.TypeBool, Default: false},
{Name: "default_mapped_model", Type: field.TypeString, Size: 100, Default: ""}, {Name: "default_mapped_model", Type: field.TypeString, Size: 100, Default: ""},
{Name: "messages_dispatch_model_config", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}}, {Name: "messages_dispatch_model_config", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
{Name: "rpm_limit", Type: field.TypeInt, Default: 0},
} }
// GroupsTable holds the schema information for the "groups" table. // GroupsTable holds the schema information for the "groups" table.
GroupsTable = &schema.Table{ GroupsTable = &schema.Table{
...@@ -1447,6 +1448,7 @@ var ( ...@@ -1447,6 +1448,7 @@ var (
{Name: "balance_notify_threshold", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}}, {Name: "balance_notify_threshold", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "balance_notify_extra_emails", Type: field.TypeString, Default: "[]", SchemaType: map[string]string{"postgres": "text"}}, {Name: "balance_notify_extra_emails", Type: field.TypeString, Default: "[]", SchemaType: map[string]string{"postgres": "text"}},
{Name: "total_recharged", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,8)"}}, {Name: "total_recharged", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "rpm_limit", Type: field.TypeInt, Default: 0},
} }
// UsersTable holds the schema information for the "users" table. // UsersTable holds the schema information for the "users" table.
UsersTable = &schema.Table{ UsersTable = &schema.Table{
......
...@@ -14787,6 +14787,8 @@ type GroupMutation struct { ...@@ -14787,6 +14787,8 @@ type GroupMutation struct {
require_privacy_set *bool require_privacy_set *bool
default_mapped_model *string default_mapped_model *string
messages_dispatch_model_config *domain.OpenAIMessagesDispatchModelConfig messages_dispatch_model_config *domain.OpenAIMessagesDispatchModelConfig
rpm_limit *int
addrpm_limit *int
clearedFields map[string]struct{} clearedFields map[string]struct{}
api_keys map[int64]struct{} api_keys map[int64]struct{}
removedapi_keys map[int64]struct{} removedapi_keys map[int64]struct{}
...@@ -16375,6 +16377,62 @@ func (m *GroupMutation) ResetMessagesDispatchModelConfig() { ...@@ -16375,6 +16377,62 @@ func (m *GroupMutation) ResetMessagesDispatchModelConfig() {
m.messages_dispatch_model_config = nil m.messages_dispatch_model_config = nil
} }
   
// SetRpmLimit sets the "rpm_limit" field.
func (m *GroupMutation) SetRpmLimit(i int) {
m.rpm_limit = &i
m.addrpm_limit = nil
}
// RpmLimit returns the value of the "rpm_limit" field in the mutation.
func (m *GroupMutation) RpmLimit() (r int, exists bool) {
v := m.rpm_limit
if v == nil {
return
}
return *v, true
}
// OldRpmLimit returns the old "rpm_limit" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldRpmLimit(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRpmLimit is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRpmLimit requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRpmLimit: %w", err)
}
return oldValue.RpmLimit, nil
}
// AddRpmLimit adds i to the "rpm_limit" field.
func (m *GroupMutation) AddRpmLimit(i int) {
if m.addrpm_limit != nil {
*m.addrpm_limit += i
} else {
m.addrpm_limit = &i
}
}
// AddedRpmLimit returns the value that was added to the "rpm_limit" field in this mutation.
func (m *GroupMutation) AddedRpmLimit() (r int, exists bool) {
v := m.addrpm_limit
if v == nil {
return
}
return *v, true
}
// ResetRpmLimit resets all changes to the "rpm_limit" field.
func (m *GroupMutation) ResetRpmLimit() {
m.rpm_limit = nil
m.addrpm_limit = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) { func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil { if m.api_keys == nil {
...@@ -16733,7 +16791,7 @@ func (m *GroupMutation) Type() string { ...@@ -16733,7 +16791,7 @@ func (m *GroupMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *GroupMutation) Fields() []string { func (m *GroupMutation) Fields() []string {
fields := make([]string, 0, 30) fields := make([]string, 0, 31)
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, group.FieldCreatedAt) fields = append(fields, group.FieldCreatedAt)
} }
...@@ -16824,6 +16882,9 @@ func (m *GroupMutation) Fields() []string { ...@@ -16824,6 +16882,9 @@ func (m *GroupMutation) Fields() []string {
if m.messages_dispatch_model_config != nil { if m.messages_dispatch_model_config != nil {
fields = append(fields, group.FieldMessagesDispatchModelConfig) fields = append(fields, group.FieldMessagesDispatchModelConfig)
} }
if m.rpm_limit != nil {
fields = append(fields, group.FieldRpmLimit)
}
return fields return fields
} }
   
...@@ -16892,6 +16953,8 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) { ...@@ -16892,6 +16953,8 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
return m.DefaultMappedModel() return m.DefaultMappedModel()
case group.FieldMessagesDispatchModelConfig: case group.FieldMessagesDispatchModelConfig:
return m.MessagesDispatchModelConfig() return m.MessagesDispatchModelConfig()
case group.FieldRpmLimit:
return m.RpmLimit()
} }
return nil, false return nil, false
} }
...@@ -16961,6 +17024,8 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e ...@@ -16961,6 +17024,8 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
return m.OldDefaultMappedModel(ctx) return m.OldDefaultMappedModel(ctx)
case group.FieldMessagesDispatchModelConfig: case group.FieldMessagesDispatchModelConfig:
return m.OldMessagesDispatchModelConfig(ctx) return m.OldMessagesDispatchModelConfig(ctx)
case group.FieldRpmLimit:
return m.OldRpmLimit(ctx)
} }
return nil, fmt.Errorf("unknown Group field %s", name) return nil, fmt.Errorf("unknown Group field %s", name)
} }
...@@ -17180,6 +17245,13 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error { ...@@ -17180,6 +17245,13 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
} }
m.SetMessagesDispatchModelConfig(v) m.SetMessagesDispatchModelConfig(v)
return nil return nil
case group.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRpmLimit(v)
return nil
} }
return fmt.Errorf("unknown Group field %s", name) return fmt.Errorf("unknown Group field %s", name)
} }
...@@ -17221,6 +17293,9 @@ func (m *GroupMutation) AddedFields() []string { ...@@ -17221,6 +17293,9 @@ func (m *GroupMutation) AddedFields() []string {
if m.addsort_order != nil { if m.addsort_order != nil {
fields = append(fields, group.FieldSortOrder) fields = append(fields, group.FieldSortOrder)
} }
if m.addrpm_limit != nil {
fields = append(fields, group.FieldRpmLimit)
}
return fields return fields
} }
   
...@@ -17251,6 +17326,8 @@ func (m *GroupMutation) AddedField(name string) (ent.Value, bool) { ...@@ -17251,6 +17326,8 @@ func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedFallbackGroupIDOnInvalidRequest() return m.AddedFallbackGroupIDOnInvalidRequest()
case group.FieldSortOrder: case group.FieldSortOrder:
return m.AddedSortOrder() return m.AddedSortOrder()
case group.FieldRpmLimit:
return m.AddedRpmLimit()
} }
return nil, false return nil, false
} }
...@@ -17337,6 +17414,13 @@ func (m *GroupMutation) AddField(name string, value ent.Value) error { ...@@ -17337,6 +17414,13 @@ func (m *GroupMutation) AddField(name string, value ent.Value) error {
} }
m.AddSortOrder(v) m.AddSortOrder(v)
return nil return nil
case group.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRpmLimit(v)
return nil
} }
return fmt.Errorf("unknown Group numeric field %s", name) return fmt.Errorf("unknown Group numeric field %s", name)
} }
...@@ -17523,6 +17607,9 @@ func (m *GroupMutation) ResetField(name string) error { ...@@ -17523,6 +17607,9 @@ func (m *GroupMutation) ResetField(name string) error {
case group.FieldMessagesDispatchModelConfig: case group.FieldMessagesDispatchModelConfig:
m.ResetMessagesDispatchModelConfig() m.ResetMessagesDispatchModelConfig()
return nil return nil
case group.FieldRpmLimit:
m.ResetRpmLimit()
return nil
} }
return fmt.Errorf("unknown Group field %s", name) return fmt.Errorf("unknown Group field %s", name)
} }
...@@ -37366,6 +37453,8 @@ type UserMutation struct { ...@@ -37366,6 +37453,8 @@ type UserMutation struct {
balance_notify_extra_emails *string balance_notify_extra_emails *string
total_recharged *float64 total_recharged *float64
addtotal_recharged *float64 addtotal_recharged *float64
rpm_limit *int
addrpm_limit *int
clearedFields map[string]struct{} clearedFields map[string]struct{}
api_keys map[int64]struct{} api_keys map[int64]struct{}
removedapi_keys map[int64]struct{} removedapi_keys map[int64]struct{}
...@@ -38457,6 +38546,62 @@ func (m *UserMutation) ResetTotalRecharged() { ...@@ -38457,6 +38546,62 @@ func (m *UserMutation) ResetTotalRecharged() {
m.addtotal_recharged = nil m.addtotal_recharged = nil
} }
   
// SetRpmLimit sets the "rpm_limit" field.
func (m *UserMutation) SetRpmLimit(i int) {
m.rpm_limit = &i
m.addrpm_limit = nil
}
// RpmLimit returns the value of the "rpm_limit" field in the mutation.
func (m *UserMutation) RpmLimit() (r int, exists bool) {
v := m.rpm_limit
if v == nil {
return
}
return *v, true
}
// OldRpmLimit returns the old "rpm_limit" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldRpmLimit(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRpmLimit is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRpmLimit requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRpmLimit: %w", err)
}
return oldValue.RpmLimit, nil
}
// AddRpmLimit adds i to the "rpm_limit" field.
func (m *UserMutation) AddRpmLimit(i int) {
if m.addrpm_limit != nil {
*m.addrpm_limit += i
} else {
m.addrpm_limit = &i
}
}
// AddedRpmLimit returns the value that was added to the "rpm_limit" field in this mutation.
func (m *UserMutation) AddedRpmLimit() (r int, exists bool) {
v := m.addrpm_limit
if v == nil {
return
}
return *v, true
}
// ResetRpmLimit resets all changes to the "rpm_limit" field.
func (m *UserMutation) ResetRpmLimit() {
m.rpm_limit = nil
m.addrpm_limit = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *UserMutation) AddAPIKeyIDs(ids ...int64) { func (m *UserMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil { if m.api_keys == nil {
...@@ -39139,7 +39284,7 @@ func (m *UserMutation) Type() string { ...@@ -39139,7 +39284,7 @@ func (m *UserMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *UserMutation) Fields() []string { func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 22) fields := make([]string, 0, 23)
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, user.FieldCreatedAt) fields = append(fields, user.FieldCreatedAt)
} }
...@@ -39206,6 +39351,9 @@ func (m *UserMutation) Fields() []string { ...@@ -39206,6 +39351,9 @@ func (m *UserMutation) Fields() []string {
if m.total_recharged != nil { if m.total_recharged != nil {
fields = append(fields, user.FieldTotalRecharged) fields = append(fields, user.FieldTotalRecharged)
} }
if m.rpm_limit != nil {
fields = append(fields, user.FieldRpmLimit)
}
return fields return fields
} }
   
...@@ -39258,6 +39406,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { ...@@ -39258,6 +39406,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
return m.BalanceNotifyExtraEmails() return m.BalanceNotifyExtraEmails()
case user.FieldTotalRecharged: case user.FieldTotalRecharged:
return m.TotalRecharged() return m.TotalRecharged()
case user.FieldRpmLimit:
return m.RpmLimit()
} }
return nil, false return nil, false
} }
...@@ -39311,6 +39461,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er ...@@ -39311,6 +39461,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldBalanceNotifyExtraEmails(ctx) return m.OldBalanceNotifyExtraEmails(ctx)
case user.FieldTotalRecharged: case user.FieldTotalRecharged:
return m.OldTotalRecharged(ctx) return m.OldTotalRecharged(ctx)
case user.FieldRpmLimit:
return m.OldRpmLimit(ctx)
} }
return nil, fmt.Errorf("unknown User field %s", name) return nil, fmt.Errorf("unknown User field %s", name)
} }
...@@ -39474,6 +39626,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { ...@@ -39474,6 +39626,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
} }
m.SetTotalRecharged(v) m.SetTotalRecharged(v)
return nil return nil
case user.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRpmLimit(v)
return nil
} }
return fmt.Errorf("unknown User field %s", name) return fmt.Errorf("unknown User field %s", name)
} }
...@@ -39494,6 +39653,9 @@ func (m *UserMutation) AddedFields() []string { ...@@ -39494,6 +39653,9 @@ func (m *UserMutation) AddedFields() []string {
if m.addtotal_recharged != nil { if m.addtotal_recharged != nil {
fields = append(fields, user.FieldTotalRecharged) fields = append(fields, user.FieldTotalRecharged)
} }
if m.addrpm_limit != nil {
fields = append(fields, user.FieldRpmLimit)
}
return fields return fields
} }
   
...@@ -39510,6 +39672,8 @@ func (m *UserMutation) AddedField(name string) (ent.Value, bool) { ...@@ -39510,6 +39672,8 @@ func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedBalanceNotifyThreshold() return m.AddedBalanceNotifyThreshold()
case user.FieldTotalRecharged: case user.FieldTotalRecharged:
return m.AddedTotalRecharged() return m.AddedTotalRecharged()
case user.FieldRpmLimit:
return m.AddedRpmLimit()
} }
return nil, false return nil, false
} }
...@@ -39547,6 +39711,13 @@ func (m *UserMutation) AddField(name string, value ent.Value) error { ...@@ -39547,6 +39711,13 @@ func (m *UserMutation) AddField(name string, value ent.Value) error {
} }
m.AddTotalRecharged(v) m.AddTotalRecharged(v)
return nil return nil
case user.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRpmLimit(v)
return nil
} }
return fmt.Errorf("unknown User numeric field %s", name) return fmt.Errorf("unknown User numeric field %s", name)
} }
...@@ -39679,6 +39850,9 @@ func (m *UserMutation) ResetField(name string) error { ...@@ -39679,6 +39850,9 @@ func (m *UserMutation) ResetField(name string) error {
case user.FieldTotalRecharged: case user.FieldTotalRecharged:
m.ResetTotalRecharged() m.ResetTotalRecharged()
return nil return nil
case user.FieldRpmLimit:
m.ResetRpmLimit()
return nil
} }
return fmt.Errorf("unknown User field %s", name) return fmt.Errorf("unknown User field %s", name)
} }
...@@ -845,6 +845,10 @@ func init() { ...@@ -845,6 +845,10 @@ func init() {
groupDescMessagesDispatchModelConfig := groupFields[26].Descriptor() groupDescMessagesDispatchModelConfig := groupFields[26].Descriptor()
// group.DefaultMessagesDispatchModelConfig holds the default value on creation for the messages_dispatch_model_config field. // group.DefaultMessagesDispatchModelConfig holds the default value on creation for the messages_dispatch_model_config field.
group.DefaultMessagesDispatchModelConfig = groupDescMessagesDispatchModelConfig.Default.(domain.OpenAIMessagesDispatchModelConfig) group.DefaultMessagesDispatchModelConfig = groupDescMessagesDispatchModelConfig.Default.(domain.OpenAIMessagesDispatchModelConfig)
// groupDescRpmLimit is the schema descriptor for rpm_limit field.
groupDescRpmLimit := groupFields[27].Descriptor()
// group.DefaultRpmLimit holds the default value on creation for the rpm_limit field.
group.DefaultRpmLimit = groupDescRpmLimit.Default.(int)
idempotencyrecordMixin := schema.IdempotencyRecord{}.Mixin() idempotencyrecordMixin := schema.IdempotencyRecord{}.Mixin()
idempotencyrecordMixinFields0 := idempotencyrecordMixin[0].Fields() idempotencyrecordMixinFields0 := idempotencyrecordMixin[0].Fields()
_ = idempotencyrecordMixinFields0 _ = idempotencyrecordMixinFields0
...@@ -1825,6 +1829,10 @@ func init() { ...@@ -1825,6 +1829,10 @@ func init() {
userDescTotalRecharged := userFields[18].Descriptor() userDescTotalRecharged := userFields[18].Descriptor()
// user.DefaultTotalRecharged holds the default value on creation for the total_recharged field. // user.DefaultTotalRecharged holds the default value on creation for the total_recharged field.
user.DefaultTotalRecharged = userDescTotalRecharged.Default.(float64) user.DefaultTotalRecharged = userDescTotalRecharged.Default.(float64)
// userDescRpmLimit is the schema descriptor for rpm_limit field.
userDescRpmLimit := userFields[19].Descriptor()
// user.DefaultRpmLimit holds the default value on creation for the rpm_limit field.
user.DefaultRpmLimit = userDescRpmLimit.Default.(int)
userallowedgroupFields := schema.UserAllowedGroup{}.Fields() userallowedgroupFields := schema.UserAllowedGroup{}.Fields()
_ = userallowedgroupFields _ = userallowedgroupFields
// userallowedgroupDescCreatedAt is the schema descriptor for created_at field. // userallowedgroupDescCreatedAt is the schema descriptor for created_at field.
......
...@@ -145,6 +145,11 @@ func (Group) Fields() []ent.Field { ...@@ -145,6 +145,11 @@ func (Group) Fields() []ent.Field {
Default(domain.OpenAIMessagesDispatchModelConfig{}). Default(domain.OpenAIMessagesDispatchModelConfig{}).
SchemaType(map[string]string{dialect.Postgres: "jsonb"}). SchemaType(map[string]string{dialect.Postgres: "jsonb"}).
Comment("OpenAI Messages 调度模型配置:按 Claude 系列/精确模型映射到目标 GPT 模型"), Comment("OpenAI Messages 调度模型配置:按 Claude 系列/精确模型映射到目标 GPT 模型"),
// 分组级每分钟请求数上限(0 = 不限制)。设置后优先于用户级兜底生效。
field.Int("rpm_limit").
Default(0).
Comment("分组 RPM 上限,0 表示不限制;设置后接管该分组用户的限流"),
} }
} }
......
...@@ -108,6 +108,10 @@ func (User) Fields() []ent.Field { ...@@ -108,6 +108,10 @@ func (User) Fields() []ent.Field {
field.Float("total_recharged"). field.Float("total_recharged").
SchemaType(map[string]string{dialect.Postgres: "decimal(20,8)"}). SchemaType(map[string]string{dialect.Postgres: "decimal(20,8)"}).
Default(0), Default(0),
// 用户级每分钟请求数上限(0 = 不限制)。仅当所在分组未设置 rpm_limit 时作为兜底生效。
field.Int("rpm_limit").
Default(0),
} }
} }
......
...@@ -61,6 +61,8 @@ type User struct { ...@@ -61,6 +61,8 @@ type User struct {
BalanceNotifyExtraEmails string `json:"balance_notify_extra_emails,omitempty"` BalanceNotifyExtraEmails string `json:"balance_notify_extra_emails,omitempty"`
// TotalRecharged holds the value of the "total_recharged" field. // TotalRecharged holds the value of the "total_recharged" field.
TotalRecharged float64 `json:"total_recharged,omitempty"` TotalRecharged float64 `json:"total_recharged,omitempty"`
// RpmLimit holds the value of the "rpm_limit" field.
RpmLimit int `json:"rpm_limit,omitempty"`
// Edges holds the relations/edges for other nodes in the graph. // Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UserQuery when eager-loading is set. // The values are being populated by the UserQuery when eager-loading is set.
Edges UserEdges `json:"edges"` Edges UserEdges `json:"edges"`
...@@ -226,7 +228,7 @@ func (*User) scanValues(columns []string) ([]any, error) { ...@@ -226,7 +228,7 @@ func (*User) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool) values[i] = new(sql.NullBool)
case user.FieldBalance, user.FieldBalanceNotifyThreshold, user.FieldTotalRecharged: case user.FieldBalance, user.FieldBalanceNotifyThreshold, user.FieldTotalRecharged:
values[i] = new(sql.NullFloat64) values[i] = new(sql.NullFloat64)
case user.FieldID, user.FieldConcurrency: case user.FieldID, user.FieldConcurrency, user.FieldRpmLimit:
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case user.FieldEmail, user.FieldPasswordHash, user.FieldRole, user.FieldStatus, user.FieldUsername, user.FieldNotes, user.FieldTotpSecretEncrypted, user.FieldSignupSource, user.FieldBalanceNotifyThresholdType, user.FieldBalanceNotifyExtraEmails: case user.FieldEmail, user.FieldPasswordHash, user.FieldRole, user.FieldStatus, user.FieldUsername, user.FieldNotes, user.FieldTotpSecretEncrypted, user.FieldSignupSource, user.FieldBalanceNotifyThresholdType, user.FieldBalanceNotifyExtraEmails:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
...@@ -391,6 +393,12 @@ func (_m *User) assignValues(columns []string, values []any) error { ...@@ -391,6 +393,12 @@ func (_m *User) assignValues(columns []string, values []any) error {
} else if value.Valid { } else if value.Valid {
_m.TotalRecharged = value.Float64 _m.TotalRecharged = value.Float64
} }
case user.FieldRpmLimit:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field rpm_limit", values[i])
} else if value.Valid {
_m.RpmLimit = int(value.Int64)
}
default: default:
_m.selectValues.Set(columns[i], values[i]) _m.selectValues.Set(columns[i], values[i])
} }
...@@ -569,6 +577,9 @@ func (_m *User) String() string { ...@@ -569,6 +577,9 @@ func (_m *User) String() string {
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("total_recharged=") builder.WriteString("total_recharged=")
builder.WriteString(fmt.Sprintf("%v", _m.TotalRecharged)) builder.WriteString(fmt.Sprintf("%v", _m.TotalRecharged))
builder.WriteString(", ")
builder.WriteString("rpm_limit=")
builder.WriteString(fmt.Sprintf("%v", _m.RpmLimit))
builder.WriteByte(')') builder.WriteByte(')')
return builder.String() return builder.String()
} }
......
...@@ -59,6 +59,8 @@ const ( ...@@ -59,6 +59,8 @@ const (
FieldBalanceNotifyExtraEmails = "balance_notify_extra_emails" FieldBalanceNotifyExtraEmails = "balance_notify_extra_emails"
// FieldTotalRecharged holds the string denoting the total_recharged field in the database. // FieldTotalRecharged holds the string denoting the total_recharged field in the database.
FieldTotalRecharged = "total_recharged" FieldTotalRecharged = "total_recharged"
// FieldRpmLimit holds the string denoting the rpm_limit field in the database.
FieldRpmLimit = "rpm_limit"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations. // EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys = "api_keys" EdgeAPIKeys = "api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations. // EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...@@ -203,6 +205,7 @@ var Columns = []string{ ...@@ -203,6 +205,7 @@ var Columns = []string{
FieldBalanceNotifyThreshold, FieldBalanceNotifyThreshold,
FieldBalanceNotifyExtraEmails, FieldBalanceNotifyExtraEmails,
FieldTotalRecharged, FieldTotalRecharged,
FieldRpmLimit,
} }
var ( var (
...@@ -271,6 +274,8 @@ var ( ...@@ -271,6 +274,8 @@ var (
DefaultBalanceNotifyExtraEmails string DefaultBalanceNotifyExtraEmails string
// DefaultTotalRecharged holds the default value on creation for the "total_recharged" field. // DefaultTotalRecharged holds the default value on creation for the "total_recharged" field.
DefaultTotalRecharged float64 DefaultTotalRecharged float64
// DefaultRpmLimit holds the default value on creation for the "rpm_limit" field.
DefaultRpmLimit int
) )
// OrderOption defines the ordering options for the User queries. // OrderOption defines the ordering options for the User queries.
...@@ -391,6 +396,11 @@ func ByTotalRecharged(opts ...sql.OrderTermOption) OrderOption { ...@@ -391,6 +396,11 @@ func ByTotalRecharged(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTotalRecharged, opts...).ToFunc() return sql.OrderByField(FieldTotalRecharged, opts...).ToFunc()
} }
// ByRpmLimit orders the results by the rpm_limit field.
func ByRpmLimit(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRpmLimit, opts...).ToFunc()
}
// ByAPIKeysCount orders the results by api_keys count. // ByAPIKeysCount orders the results by api_keys count.
func ByAPIKeysCount(opts ...sql.OrderTermOption) OrderOption { func ByAPIKeysCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) { return func(s *sql.Selector) {
......
...@@ -165,6 +165,11 @@ func TotalRecharged(v float64) predicate.User { ...@@ -165,6 +165,11 @@ func TotalRecharged(v float64) predicate.User {
return predicate.User(sql.FieldEQ(FieldTotalRecharged, v)) return predicate.User(sql.FieldEQ(FieldTotalRecharged, v))
} }
// RpmLimit applies equality check predicate on the "rpm_limit" field. It's identical to RpmLimitEQ.
func RpmLimit(v int) predicate.User {
return predicate.User(sql.FieldEQ(FieldRpmLimit, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.User { func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
...@@ -1295,6 +1300,46 @@ func TotalRechargedLTE(v float64) predicate.User { ...@@ -1295,6 +1300,46 @@ func TotalRechargedLTE(v float64) predicate.User {
return predicate.User(sql.FieldLTE(FieldTotalRecharged, v)) return predicate.User(sql.FieldLTE(FieldTotalRecharged, v))
} }
// RpmLimitEQ applies the EQ predicate on the "rpm_limit" field.
func RpmLimitEQ(v int) predicate.User {
return predicate.User(sql.FieldEQ(FieldRpmLimit, v))
}
// RpmLimitNEQ applies the NEQ predicate on the "rpm_limit" field.
func RpmLimitNEQ(v int) predicate.User {
return predicate.User(sql.FieldNEQ(FieldRpmLimit, v))
}
// RpmLimitIn applies the In predicate on the "rpm_limit" field.
func RpmLimitIn(vs ...int) predicate.User {
return predicate.User(sql.FieldIn(FieldRpmLimit, vs...))
}
// RpmLimitNotIn applies the NotIn predicate on the "rpm_limit" field.
func RpmLimitNotIn(vs ...int) predicate.User {
return predicate.User(sql.FieldNotIn(FieldRpmLimit, vs...))
}
// RpmLimitGT applies the GT predicate on the "rpm_limit" field.
func RpmLimitGT(v int) predicate.User {
return predicate.User(sql.FieldGT(FieldRpmLimit, v))
}
// RpmLimitGTE applies the GTE predicate on the "rpm_limit" field.
func RpmLimitGTE(v int) predicate.User {
return predicate.User(sql.FieldGTE(FieldRpmLimit, v))
}
// RpmLimitLT applies the LT predicate on the "rpm_limit" field.
func RpmLimitLT(v int) predicate.User {
return predicate.User(sql.FieldLT(FieldRpmLimit, v))
}
// RpmLimitLTE applies the LTE predicate on the "rpm_limit" field.
func RpmLimitLTE(v int) predicate.User {
return predicate.User(sql.FieldLTE(FieldRpmLimit, v))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge. // HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func HasAPIKeys() predicate.User { func HasAPIKeys() predicate.User {
return predicate.User(func(s *sql.Selector) { return predicate.User(func(s *sql.Selector) {
......
...@@ -325,6 +325,20 @@ func (_c *UserCreate) SetNillableTotalRecharged(v *float64) *UserCreate { ...@@ -325,6 +325,20 @@ func (_c *UserCreate) SetNillableTotalRecharged(v *float64) *UserCreate {
return _c return _c
} }
// SetRpmLimit sets the "rpm_limit" field.
func (_c *UserCreate) SetRpmLimit(v int) *UserCreate {
_c.mutation.SetRpmLimit(v)
return _c
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func (_c *UserCreate) SetNillableRpmLimit(v *int) *UserCreate {
if v != nil {
_c.SetRpmLimit(*v)
}
return _c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_c *UserCreate) AddAPIKeyIDs(ids ...int64) *UserCreate { func (_c *UserCreate) AddAPIKeyIDs(ids ...int64) *UserCreate {
_c.mutation.AddAPIKeyIDs(ids...) _c.mutation.AddAPIKeyIDs(ids...)
...@@ -604,6 +618,10 @@ func (_c *UserCreate) defaults() error { ...@@ -604,6 +618,10 @@ func (_c *UserCreate) defaults() error {
v := user.DefaultTotalRecharged v := user.DefaultTotalRecharged
_c.mutation.SetTotalRecharged(v) _c.mutation.SetTotalRecharged(v)
} }
if _, ok := _c.mutation.RpmLimit(); !ok {
v := user.DefaultRpmLimit
_c.mutation.SetRpmLimit(v)
}
return nil return nil
} }
...@@ -687,6 +705,9 @@ func (_c *UserCreate) check() error { ...@@ -687,6 +705,9 @@ func (_c *UserCreate) check() error {
if _, ok := _c.mutation.TotalRecharged(); !ok { if _, ok := _c.mutation.TotalRecharged(); !ok {
return &ValidationError{Name: "total_recharged", err: errors.New(`ent: missing required field "User.total_recharged"`)} return &ValidationError{Name: "total_recharged", err: errors.New(`ent: missing required field "User.total_recharged"`)}
} }
if _, ok := _c.mutation.RpmLimit(); !ok {
return &ValidationError{Name: "rpm_limit", err: errors.New(`ent: missing required field "User.rpm_limit"`)}
}
return nil return nil
} }
...@@ -802,6 +823,10 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { ...@@ -802,6 +823,10 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec.SetField(user.FieldTotalRecharged, field.TypeFloat64, value) _spec.SetField(user.FieldTotalRecharged, field.TypeFloat64, value)
_node.TotalRecharged = value _node.TotalRecharged = value
} }
if value, ok := _c.mutation.RpmLimit(); ok {
_spec.SetField(user.FieldRpmLimit, field.TypeInt, value)
_node.RpmLimit = value
}
if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 { if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M, Rel: sqlgraph.O2M,
...@@ -1362,6 +1387,24 @@ func (u *UserUpsert) AddTotalRecharged(v float64) *UserUpsert { ...@@ -1362,6 +1387,24 @@ func (u *UserUpsert) AddTotalRecharged(v float64) *UserUpsert {
return u return u
} }
// SetRpmLimit sets the "rpm_limit" field.
func (u *UserUpsert) SetRpmLimit(v int) *UserUpsert {
u.Set(user.FieldRpmLimit, v)
return u
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func (u *UserUpsert) UpdateRpmLimit() *UserUpsert {
u.SetExcluded(user.FieldRpmLimit)
return u
}
// AddRpmLimit adds v to the "rpm_limit" field.
func (u *UserUpsert) AddRpmLimit(v int) *UserUpsert {
u.Add(user.FieldRpmLimit, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create. // UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using: // Using this option is equivalent to using:
// //
...@@ -1771,6 +1814,27 @@ func (u *UserUpsertOne) UpdateTotalRecharged() *UserUpsertOne { ...@@ -1771,6 +1814,27 @@ func (u *UserUpsertOne) UpdateTotalRecharged() *UserUpsertOne {
}) })
} }
// SetRpmLimit sets the "rpm_limit" field.
func (u *UserUpsertOne) SetRpmLimit(v int) *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
s.SetRpmLimit(v)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func (u *UserUpsertOne) AddRpmLimit(v int) *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
s.AddRpmLimit(v)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateRpmLimit() *UserUpsertOne {
return u.Update(func(s *UserUpsert) {
s.UpdateRpmLimit()
})
}
// Exec executes the query. // Exec executes the query.
func (u *UserUpsertOne) Exec(ctx context.Context) error { func (u *UserUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 { if len(u.create.conflict) == 0 {
...@@ -2346,6 +2410,27 @@ func (u *UserUpsertBulk) UpdateTotalRecharged() *UserUpsertBulk { ...@@ -2346,6 +2410,27 @@ func (u *UserUpsertBulk) UpdateTotalRecharged() *UserUpsertBulk {
}) })
} }
// SetRpmLimit sets the "rpm_limit" field.
func (u *UserUpsertBulk) SetRpmLimit(v int) *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {
s.SetRpmLimit(v)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func (u *UserUpsertBulk) AddRpmLimit(v int) *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {
s.AddRpmLimit(v)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateRpmLimit() *UserUpsertBulk {
return u.Update(func(s *UserUpsert) {
s.UpdateRpmLimit()
})
}
// Exec executes the query. // Exec executes the query.
func (u *UserUpsertBulk) Exec(ctx context.Context) error { func (u *UserUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil { if u.create.err != nil {
......
...@@ -389,6 +389,27 @@ func (_u *UserUpdate) AddTotalRecharged(v float64) *UserUpdate { ...@@ -389,6 +389,27 @@ func (_u *UserUpdate) AddTotalRecharged(v float64) *UserUpdate {
return _u return _u
} }
// SetRpmLimit sets the "rpm_limit" field.
func (_u *UserUpdate) SetRpmLimit(v int) *UserUpdate {
_u.mutation.ResetRpmLimit()
_u.mutation.SetRpmLimit(v)
return _u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func (_u *UserUpdate) SetNillableRpmLimit(v *int) *UserUpdate {
if v != nil {
_u.SetRpmLimit(*v)
}
return _u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func (_u *UserUpdate) AddRpmLimit(v int) *UserUpdate {
_u.mutation.AddRpmLimit(v)
return _u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *UserUpdate) AddAPIKeyIDs(ids ...int64) *UserUpdate { func (_u *UserUpdate) AddAPIKeyIDs(ids ...int64) *UserUpdate {
_u.mutation.AddAPIKeyIDs(ids...) _u.mutation.AddAPIKeyIDs(ids...)
...@@ -1008,6 +1029,12 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) { ...@@ -1008,6 +1029,12 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if value, ok := _u.mutation.AddedTotalRecharged(); ok { if value, ok := _u.mutation.AddedTotalRecharged(); ok {
_spec.AddField(user.FieldTotalRecharged, field.TypeFloat64, value) _spec.AddField(user.FieldTotalRecharged, field.TypeFloat64, value)
} }
if value, ok := _u.mutation.RpmLimit(); ok {
_spec.SetField(user.FieldRpmLimit, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRpmLimit(); ok {
_spec.AddField(user.FieldRpmLimit, field.TypeInt, value)
}
if _u.mutation.APIKeysCleared() { if _u.mutation.APIKeysCleared() {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M, Rel: sqlgraph.O2M,
...@@ -1930,6 +1957,27 @@ func (_u *UserUpdateOne) AddTotalRecharged(v float64) *UserUpdateOne { ...@@ -1930,6 +1957,27 @@ func (_u *UserUpdateOne) AddTotalRecharged(v float64) *UserUpdateOne {
return _u return _u
} }
// SetRpmLimit sets the "rpm_limit" field.
func (_u *UserUpdateOne) SetRpmLimit(v int) *UserUpdateOne {
_u.mutation.ResetRpmLimit()
_u.mutation.SetRpmLimit(v)
return _u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableRpmLimit(v *int) *UserUpdateOne {
if v != nil {
_u.SetRpmLimit(*v)
}
return _u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func (_u *UserUpdateOne) AddRpmLimit(v int) *UserUpdateOne {
_u.mutation.AddRpmLimit(v)
return _u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func (_u *UserUpdateOne) AddAPIKeyIDs(ids ...int64) *UserUpdateOne { func (_u *UserUpdateOne) AddAPIKeyIDs(ids ...int64) *UserUpdateOne {
_u.mutation.AddAPIKeyIDs(ids...) _u.mutation.AddAPIKeyIDs(ids...)
...@@ -2579,6 +2627,12 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { ...@@ -2579,6 +2627,12 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if value, ok := _u.mutation.AddedTotalRecharged(); ok { if value, ok := _u.mutation.AddedTotalRecharged(); ok {
_spec.AddField(user.FieldTotalRecharged, field.TypeFloat64, value) _spec.AddField(user.FieldTotalRecharged, field.TypeFloat64, value)
} }
if value, ok := _u.mutation.RpmLimit(); ok {
_spec.SetField(user.FieldRpmLimit, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRpmLimit(); ok {
_spec.AddField(user.FieldRpmLimit, field.TypeInt, value)
}
if _u.mutation.APIKeysCleared() { if _u.mutation.APIKeysCleared() {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M, Rel: sqlgraph.O2M,
......
...@@ -104,6 +104,7 @@ require ( ...@@ -104,6 +104,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.7.0 // indirect github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.1 // indirect github.com/hashicorp/hcl/v2 v2.18.1 // indirect
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment