* fix(ops): 修复运维监控系统的关键安全和稳定性问题
## 修复内容
### P0 严重问题
1. **DNS Rebinding防护** (ops_alert_service.go)
- 实现IP钉住机制防止验证后的DNS rebinding攻击
- 自定义Transport.DialContext强制只允许拨号到验证过的公网IP
- 扩展IP黑名单,包括云metadata地址(169.254.169.254)
- 添加完整的单元测试覆盖
2. **OpsAlertService生命周期管理** (wire.go)
- 在ProvideOpsMetricsCollector中添加opsAlertService.Start()调用
- 确保stopCtx正确初始化,避免nil指针问题
- 实现防御式启动,保证服务启动顺序
3. **数据库查询排序** (ops_repo.go)
- 在ListRecentSystemMetrics中添加显式ORDER BY updated_at DESC, id DESC
- 在GetLatestSystemMetric中添加排序保证
- 避免数据库返回顺序不确定导致告警误判
### P1 重要问题
4. **并发安全** (ops_metrics_collector.go)
- 为lastGCPauseTotal字段添加sync.Mutex保护
- 防止数据竞争
5. **Goroutine泄漏** (ops_error_logger.go)
- 实现worker pool模式限制并发goroutine数量
- 使用256容量缓冲队列和10个固定worker
- 非阻塞投递,队列满时丢弃任务
6. **生命周期控制** (ops_alert_service.go)
- 添加Start/Stop方法实现优雅关闭
- 使用context控制goroutine生命周期
- 实现WaitGroup等待后台任务完成
7. **Webhook URL验证** (ops_alert_service.go)
- 防止SSRF攻击:验证scheme、禁止内网IP
- DNS解析验证,拒绝解析到私有IP的域名
- 添加8个单元测试覆盖各种攻击场景
8. **资源泄漏** (ops_repo.go)
- 修复多处defer rows.Close()问题
- 简化冗余的defer func()包装
9. **HTTP超时控制** (ops_alert_service.go)
- 创建带10秒超时的http.Client
- 添加buildWebhookHTTPClient辅助函数
- 防止HTTP请求无限期挂起
10. **数据库查询优化** (ops_repo.go)
- 将GetWindowStats的4次独立查询合并为1次CTE查询
- 减少网络往返和表扫描次数
- 显著提升性能
11. **重试机制** (ops_alert_service.go)
- 实现邮件发送重试:最多3次,指数退避(1s/2s/4s)
- 添加webhook备用通道
- 实现完整的错误处理和日志记录
12. **魔法数字** (ops_repo.go, ops_metrics_collector.go)
- 提取硬编码数字为有意义的常量
- 提高代码可读性和可维护性
## 测试验证
- ✅ go test ./internal/service -tags opsalert_unit 通过
- ✅ 所有webhook验证测试通过
- ✅ 重试机制测试通过
## 影响范围
- 运维监控系统安全性显著提升
- 系统稳定性和性能优化
- 无破坏性变更,向后兼容
* feat(ops): 运维监控系统V2 - 完整实现
## 核心功能
- 运维监控仪表盘V2(实时监控、历史趋势、告警管理)
- WebSocket实时QPS/TPS监控(30s心跳,自动重连)
- 系统指标采集(CPU、内存、延迟、错误率等)
- 多维度统计分析(按provider、model、user等维度)
- 告警规则管理(阈值配置、通知渠道)
- 错误日志追踪(详细错误信息、堆栈跟踪)
## 数据库Schema (Migration 025)
### 扩展现有表
- ops_system_metrics: 新增RED指标、错误分类、延迟指标、资源指标、业务指标
- ops_alert_rules: 新增JSONB字段(dimension_filters, notify_channels, notify_config)
### 新增表
- ops_dimension_stats: 多维度统计数据
- ops_data_retention_config: 数据保留策略配置
### 新增视图和函数
- ops_latest_metrics: 最新1分钟窗口指标(已修复字段名和window过滤)
- ops_active_alerts: 当前活跃告警(已修复字段名和状态值)
- calculate_health_score: 健康分数计算函数
## 一致性修复(98/100分)
### P0级别(阻塞Migration)
- ✅ 修复ops_latest_metrics视图字段名(latency_p99→p99_latency_ms, cpu_usage→cpu_usage_percent)
- ✅ 修复ops_active_alerts视图字段名(metric→metric_type, triggered_at→fired_at, trigger_value→metric_value, threshold→threshold_value)
- ✅ 统一告警历史表名(删除ops_alert_history,使用ops_alert_events)
- ✅ 统一API参数限制(ListMetricsHistory和ListErrorLogs的limit改为5000)
### P1级别(功能完整性)
- ✅ 修复ops_latest_metrics视图未过滤window_minutes(添加WHERE m.window_minutes = 1)
- ✅ 修复数据回填UPDATE逻辑(QPS计算改为request_count/(window_minutes*60.0))
- ✅ 添加ops_alert_rules JSONB字段后端支持(Go结构体+序列化)
### P2级别(优化)
- ✅ 前端WebSocket自动重连(指数退避1s→2s→4s→8s→16s,最大5次)
- ✅ 后端WebSocket心跳检测(30s ping,60s pong超时)
## 技术实现
### 后端 (Go)
- Handler层: ops_handler.go(REST API), ops_ws_handler.go(WebSocket)
- Service层: ops_service.go(核心逻辑), ops_cache.go(缓存), ops_alerts.go(告警)
- Repository层: ops_repo.go(数据访问), ops.go(模型定义)
- 路由: admin.go(新增ops相关路由)
- 依赖注入: wire_gen.go(自动生成)
### 前端 (Vue3 + TypeScript)
- 组件: OpsDashboardV2.vue(仪表盘主组件)
- API: ops.ts(REST API + WebSocket封装)
- 路由: index.ts(新增/admin/ops路由)
- 国际化: en.ts, zh.ts(中英文支持)
## 测试验证
- ✅ 所有Go测试通过
- ✅ Migration可正常执行
- ✅ WebSocket连接稳定
- ✅ 前后端数据结构对齐
* refactor: 代码清理和测试优化
## 测试文件优化
- 简化integration test fixtures和断言
- 优化test helper函数
- 统一测试数据格式
## 代码清理
- 移除未使用的代码和注释
- 简化concurrency_cache实现
- 优化middleware错误处理
## 小修复
- 修复gateway_handler和openai_gateway_handler的小问题
- 统一代码风格和格式
变更统计: 27个文件,292行新增,322行删除(净减少30行)
* fix(ops): 运维监控系统安全加固和功能优化
## 安全增强
- feat(security): WebSocket日志脱敏机制,防止token/api_key泄露
- feat(security): X-Forwarded-Host白名单验证,防止CSRF绕过
- feat(security): Origin策略配置化,支持strict/permissive模式
- feat(auth): WebSocket认证支持query参数传递token
## 配置优化
- feat(config): 支持环境变量配置代理信任和Origin策略
- OPS_WS_TRUST_PROXY
- OPS_WS_TRUSTED_PROXIES
- OPS_WS_ORIGIN_POLICY
- fix(ops): 错误日志查询限流从5000降至500,优化内存使用
## 架构改进
- refactor(ops): 告警服务解耦,独立运行评估定时器
- refactor(ops): OpsDashboard统一版本,移除V2分离
## 测试和文档
- test(ops): 添加WebSocket安全验证单元测试(8个测试用例)
- test(ops): 添加告警服务集成测试
- docs(api): 更新API文档,标注限流变更
- docs: 添加CHANGELOG记录breaking changes
## 修复文件
Backend:
- backend/internal/server/middleware/logger.go
- backend/internal/handler/admin/ops_handler.go
- backend/internal/handler/admin/ops_ws_handler.go
- backend/internal/server/middleware/admin_auth.go
- backend/internal/service/ops_alert_service.go
- backend/internal/service/ops_metrics_collector.go
- backend/internal/service/wire.go
Frontend:
- frontend/src/views/admin/ops/OpsDashboard.vue
- frontend/src/router/index.ts
- frontend/src/api/admin/ops.ts
Tests:
- backend/internal/handler/admin/ops_ws_handler_test.go (新增)
- backend/internal/service/ops_alert_service_integration_test.go (新增)
Docs:
- CHANGELOG.md (新增)
- docs/API-运维监控中心2.0.md (更新)
* fix(migrations): 修复calculate_health_score函数类型匹配问题
在ops_latest_metrics视图中添加显式类型转换,确保参数类型与函数签名匹配
* fix(lint): 修复golangci-lint检查发现的所有问题
- 将Redis依赖从service层移到repository层
- 添加错误检查(WebSocket连接和读取超时)
- 运行gofmt格式化代码
- 添加nil指针检查
- 删除未使用的alertService字段
修复问题:
- depguard: 3个(service层不应直接import redis)
- errcheck: 3个(未检查错误返回值)
- gofmt: 2个(代码格式问题)
- staticcheck: 4个(nil指针解引用)
- unused: 1个(未使用字段)
代码统计:
- 修改文件:11个
- 删除代码:490行
- 新增代码:105行
- 净减少:385行
1905 lines
58 KiB
Go
1905 lines
58 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/Wei-Shaw/sub2api/ent/account"
|
|
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
|
"github.com/Wei-Shaw/sub2api/ent/group"
|
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
|
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
|
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
|
"github.com/Wei-Shaw/sub2api/ent/user"
|
|
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
|
|
)
|
|
|
|
// GroupUpdate is the builder for updating Group entities.
|
|
type GroupUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *GroupMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the GroupUpdate builder.
|
|
func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *GroupUpdate) SetUpdatedAt(v time.Time) *GroupUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_u *GroupUpdate) SetDeletedAt(v time.Time) *GroupUpdate {
|
|
_u.mutation.SetDeletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableDeletedAt(v *time.Time) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetDeletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (_u *GroupUpdate) ClearDeletedAt() *GroupUpdate {
|
|
_u.mutation.ClearDeletedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *GroupUpdate) SetName(v string) *GroupUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableName(v *string) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *GroupUpdate) SetDescription(v string) *GroupUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableDescription(v *string) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *GroupUpdate) ClearDescription() *GroupUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetRateMultiplier sets the "rate_multiplier" field.
|
|
func (_u *GroupUpdate) SetRateMultiplier(v float64) *GroupUpdate {
|
|
_u.mutation.ResetRateMultiplier()
|
|
_u.mutation.SetRateMultiplier(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableRateMultiplier(v *float64) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetRateMultiplier(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddRateMultiplier adds value to the "rate_multiplier" field.
|
|
func (_u *GroupUpdate) AddRateMultiplier(v float64) *GroupUpdate {
|
|
_u.mutation.AddRateMultiplier(v)
|
|
return _u
|
|
}
|
|
|
|
// SetIsExclusive sets the "is_exclusive" field.
|
|
func (_u *GroupUpdate) SetIsExclusive(v bool) *GroupUpdate {
|
|
_u.mutation.SetIsExclusive(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsExclusive sets the "is_exclusive" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableIsExclusive(v *bool) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetIsExclusive(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *GroupUpdate) SetStatus(v string) *GroupUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableStatus(v *string) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (_u *GroupUpdate) SetPlatform(v string) *GroupUpdate {
|
|
_u.mutation.SetPlatform(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePlatform sets the "platform" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillablePlatform(v *string) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetPlatform(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSubscriptionType sets the "subscription_type" field.
|
|
func (_u *GroupUpdate) SetSubscriptionType(v string) *GroupUpdate {
|
|
_u.mutation.SetSubscriptionType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSubscriptionType sets the "subscription_type" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableSubscriptionType(v *string) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetSubscriptionType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDailyLimitUsd sets the "daily_limit_usd" field.
|
|
func (_u *GroupUpdate) SetDailyLimitUsd(v float64) *GroupUpdate {
|
|
_u.mutation.ResetDailyLimitUsd()
|
|
_u.mutation.SetDailyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableDailyLimitUsd(v *float64) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetDailyLimitUsd(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddDailyLimitUsd adds value to the "daily_limit_usd" field.
|
|
func (_u *GroupUpdate) AddDailyLimitUsd(v float64) *GroupUpdate {
|
|
_u.mutation.AddDailyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
|
|
func (_u *GroupUpdate) ClearDailyLimitUsd() *GroupUpdate {
|
|
_u.mutation.ClearDailyLimitUsd()
|
|
return _u
|
|
}
|
|
|
|
// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
|
|
func (_u *GroupUpdate) SetWeeklyLimitUsd(v float64) *GroupUpdate {
|
|
_u.mutation.ResetWeeklyLimitUsd()
|
|
_u.mutation.SetWeeklyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableWeeklyLimitUsd(v *float64) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetWeeklyLimitUsd(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
|
|
func (_u *GroupUpdate) AddWeeklyLimitUsd(v float64) *GroupUpdate {
|
|
_u.mutation.AddWeeklyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
|
|
func (_u *GroupUpdate) ClearWeeklyLimitUsd() *GroupUpdate {
|
|
_u.mutation.ClearWeeklyLimitUsd()
|
|
return _u
|
|
}
|
|
|
|
// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
|
|
func (_u *GroupUpdate) SetMonthlyLimitUsd(v float64) *GroupUpdate {
|
|
_u.mutation.ResetMonthlyLimitUsd()
|
|
_u.mutation.SetMonthlyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableMonthlyLimitUsd(v *float64) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetMonthlyLimitUsd(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
|
|
func (_u *GroupUpdate) AddMonthlyLimitUsd(v float64) *GroupUpdate {
|
|
_u.mutation.AddMonthlyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
|
|
func (_u *GroupUpdate) ClearMonthlyLimitUsd() *GroupUpdate {
|
|
_u.mutation.ClearMonthlyLimitUsd()
|
|
return _u
|
|
}
|
|
|
|
// SetDefaultValidityDays sets the "default_validity_days" field.
|
|
func (_u *GroupUpdate) SetDefaultValidityDays(v int) *GroupUpdate {
|
|
_u.mutation.ResetDefaultValidityDays()
|
|
_u.mutation.SetDefaultValidityDays(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
|
|
func (_u *GroupUpdate) SetNillableDefaultValidityDays(v *int) *GroupUpdate {
|
|
if v != nil {
|
|
_u.SetDefaultValidityDays(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddDefaultValidityDays adds value to the "default_validity_days" field.
|
|
func (_u *GroupUpdate) AddDefaultValidityDays(v int) *GroupUpdate {
|
|
_u.mutation.AddDefaultValidityDays(v)
|
|
return _u
|
|
}
|
|
|
|
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
|
|
func (_u *GroupUpdate) AddAPIKeyIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.AddAPIKeyIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAPIKeys adds the "api_keys" edges to the APIKey entity.
|
|
func (_u *GroupUpdate) AddAPIKeys(v ...*APIKey) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAPIKeyIDs(ids...)
|
|
}
|
|
|
|
// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
|
|
func (_u *GroupUpdate) AddRedeemCodeIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.AddRedeemCodeIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
|
|
func (_u *GroupUpdate) AddRedeemCodes(v ...*RedeemCode) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddRedeemCodeIDs(ids...)
|
|
}
|
|
|
|
// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
|
|
func (_u *GroupUpdate) AddSubscriptionIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.AddSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
|
|
func (_u *GroupUpdate) AddSubscriptions(v ...*UserSubscription) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
|
|
func (_u *GroupUpdate) AddUsageLogIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.AddUsageLogIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
|
|
func (_u *GroupUpdate) AddUsageLogs(v ...*UsageLog) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddUsageLogIDs(ids...)
|
|
}
|
|
|
|
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
|
|
func (_u *GroupUpdate) AddAccountIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.AddAccountIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAccounts adds the "accounts" edges to the Account entity.
|
|
func (_u *GroupUpdate) AddAccounts(v ...*Account) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAccountIDs(ids...)
|
|
}
|
|
|
|
// AddAllowedUserIDs adds the "allowed_users" edge to the User entity by IDs.
|
|
func (_u *GroupUpdate) AddAllowedUserIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.AddAllowedUserIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAllowedUsers adds the "allowed_users" edges to the User entity.
|
|
func (_u *GroupUpdate) AddAllowedUsers(v ...*User) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAllowedUserIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the GroupMutation object of the builder.
|
|
func (_u *GroupUpdate) Mutation() *GroupMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearAPIKeys clears all "api_keys" edges to the APIKey entity.
|
|
func (_u *GroupUpdate) ClearAPIKeys() *GroupUpdate {
|
|
_u.mutation.ClearAPIKeys()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAPIKeyIDs removes the "api_keys" edge to APIKey entities by IDs.
|
|
func (_u *GroupUpdate) RemoveAPIKeyIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.RemoveAPIKeyIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAPIKeys removes "api_keys" edges to APIKey entities.
|
|
func (_u *GroupUpdate) RemoveAPIKeys(v ...*APIKey) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAPIKeyIDs(ids...)
|
|
}
|
|
|
|
// ClearRedeemCodes clears all "redeem_codes" edges to the RedeemCode entity.
|
|
func (_u *GroupUpdate) ClearRedeemCodes() *GroupUpdate {
|
|
_u.mutation.ClearRedeemCodes()
|
|
return _u
|
|
}
|
|
|
|
// RemoveRedeemCodeIDs removes the "redeem_codes" edge to RedeemCode entities by IDs.
|
|
func (_u *GroupUpdate) RemoveRedeemCodeIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.RemoveRedeemCodeIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveRedeemCodes removes "redeem_codes" edges to RedeemCode entities.
|
|
func (_u *GroupUpdate) RemoveRedeemCodes(v ...*RedeemCode) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveRedeemCodeIDs(ids...)
|
|
}
|
|
|
|
// ClearSubscriptions clears all "subscriptions" edges to the UserSubscription entity.
|
|
func (_u *GroupUpdate) ClearSubscriptions() *GroupUpdate {
|
|
_u.mutation.ClearSubscriptions()
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptionIDs removes the "subscriptions" edge to UserSubscription entities by IDs.
|
|
func (_u *GroupUpdate) RemoveSubscriptionIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.RemoveSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptions removes "subscriptions" edges to UserSubscription entities.
|
|
func (_u *GroupUpdate) RemoveSubscriptions(v ...*UserSubscription) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
|
|
func (_u *GroupUpdate) ClearUsageLogs() *GroupUpdate {
|
|
_u.mutation.ClearUsageLogs()
|
|
return _u
|
|
}
|
|
|
|
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
|
|
func (_u *GroupUpdate) RemoveUsageLogIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.RemoveUsageLogIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
|
|
func (_u *GroupUpdate) RemoveUsageLogs(v ...*UsageLog) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveUsageLogIDs(ids...)
|
|
}
|
|
|
|
// ClearAccounts clears all "accounts" edges to the Account entity.
|
|
func (_u *GroupUpdate) ClearAccounts() *GroupUpdate {
|
|
_u.mutation.ClearAccounts()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
|
|
func (_u *GroupUpdate) RemoveAccountIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.RemoveAccountIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAccounts removes "accounts" edges to Account entities.
|
|
func (_u *GroupUpdate) RemoveAccounts(v ...*Account) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAccountIDs(ids...)
|
|
}
|
|
|
|
// ClearAllowedUsers clears all "allowed_users" edges to the User entity.
|
|
func (_u *GroupUpdate) ClearAllowedUsers() *GroupUpdate {
|
|
_u.mutation.ClearAllowedUsers()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAllowedUserIDs removes the "allowed_users" edge to User entities by IDs.
|
|
func (_u *GroupUpdate) RemoveAllowedUserIDs(ids ...int64) *GroupUpdate {
|
|
_u.mutation.RemoveAllowedUserIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAllowedUsers removes "allowed_users" edges to User entities.
|
|
func (_u *GroupUpdate) RemoveAllowedUsers(v ...*User) *GroupUpdate {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAllowedUserIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *GroupUpdate) Save(ctx context.Context) (int, error) {
|
|
if err := _u.defaults(); err != nil {
|
|
return 0, err
|
|
}
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *GroupUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *GroupUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *GroupUpdate) 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 *GroupUpdate) defaults() error {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
if group.UpdateDefaultUpdatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized group.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := group.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *GroupUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := group.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := group.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Group.status": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Platform(); ok {
|
|
if err := group.PlatformValidator(v); err != nil {
|
|
return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Group.platform": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.SubscriptionType(); ok {
|
|
if err := group.SubscriptionTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "subscription_type", err: fmt.Errorf(`ent: validator failed for field "Group.subscription_type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.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(group.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.DeletedAt(); ok {
|
|
_spec.SetField(group.FieldDeletedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DeletedAtCleared() {
|
|
_spec.ClearField(group.FieldDeletedAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(group.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(group.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(group.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.RateMultiplier(); ok {
|
|
_spec.SetField(group.FieldRateMultiplier, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedRateMultiplier(); ok {
|
|
_spec.AddField(group.FieldRateMultiplier, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.IsExclusive(); ok {
|
|
_spec.SetField(group.FieldIsExclusive, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(group.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Platform(); ok {
|
|
_spec.SetField(group.FieldPlatform, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.SubscriptionType(); ok {
|
|
_spec.SetField(group.FieldSubscriptionType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.DailyLimitUsd(); ok {
|
|
_spec.SetField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
|
|
_spec.AddField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.DailyLimitUsdCleared() {
|
|
_spec.ClearField(group.FieldDailyLimitUsd, field.TypeFloat64)
|
|
}
|
|
if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
|
|
_spec.SetField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
|
|
_spec.AddField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.WeeklyLimitUsdCleared() {
|
|
_spec.ClearField(group.FieldWeeklyLimitUsd, field.TypeFloat64)
|
|
}
|
|
if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
|
|
_spec.SetField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
|
|
_spec.AddField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.MonthlyLimitUsdCleared() {
|
|
_spec.ClearField(group.FieldMonthlyLimitUsd, field.TypeFloat64)
|
|
}
|
|
if value, ok := _u.mutation.DefaultValidityDays(); ok {
|
|
_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedDefaultValidityDays(); ok {
|
|
_spec.AddField(group.FieldDefaultValidityDays, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.APIKeysCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.APIKeysTable,
|
|
Columns: []string{group.APIKeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAPIKeysIDs(); len(nodes) > 0 && !_u.mutation.APIKeysCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.APIKeysTable,
|
|
Columns: []string{group.APIKeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.APIKeysIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.APIKeysTable,
|
|
Columns: []string{group.APIKeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.RedeemCodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.RedeemCodesTable,
|
|
Columns: []string{group.RedeemCodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedRedeemCodesIDs(); len(nodes) > 0 && !_u.mutation.RedeemCodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.RedeemCodesTable,
|
|
Columns: []string{group.RedeemCodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RedeemCodesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.RedeemCodesTable,
|
|
Columns: []string{group.RedeemCodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.SubscriptionsTable,
|
|
Columns: []string{group.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.SubscriptionsTable,
|
|
Columns: []string{group.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.SubscriptionsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.SubscriptionsTable,
|
|
Columns: []string{group.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.UsageLogsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.UsageLogsTable,
|
|
Columns: []string{group.UsageLogsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.UsageLogsTable,
|
|
Columns: []string{group.UsageLogsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.UsageLogsTable,
|
|
Columns: []string{group.UsageLogsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.AccountsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AccountsTable,
|
|
Columns: group.AccountsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AccountsTable,
|
|
Columns: group.AccountsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AccountsTable,
|
|
Columns: group.AccountsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.AllowedUsersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AllowedUsersTable,
|
|
Columns: group.AllowedUsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAllowedUsersIDs(); len(nodes) > 0 && !_u.mutation.AllowedUsersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AllowedUsersTable,
|
|
Columns: group.AllowedUsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.AllowedUsersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AllowedUsersTable,
|
|
Columns: group.AllowedUsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{group.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// GroupUpdateOne is the builder for updating a single Group entity.
|
|
type GroupUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *GroupMutation
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *GroupUpdateOne) SetUpdatedAt(v time.Time) *GroupUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_u *GroupUpdateOne) SetDeletedAt(v time.Time) *GroupUpdateOne {
|
|
_u.mutation.SetDeletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableDeletedAt(v *time.Time) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetDeletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (_u *GroupUpdateOne) ClearDeletedAt() *GroupUpdateOne {
|
|
_u.mutation.ClearDeletedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableName(v *string) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *GroupUpdateOne) SetDescription(v string) *GroupUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableDescription(v *string) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *GroupUpdateOne) ClearDescription() *GroupUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetRateMultiplier sets the "rate_multiplier" field.
|
|
func (_u *GroupUpdateOne) SetRateMultiplier(v float64) *GroupUpdateOne {
|
|
_u.mutation.ResetRateMultiplier()
|
|
_u.mutation.SetRateMultiplier(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableRateMultiplier(v *float64) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetRateMultiplier(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddRateMultiplier adds value to the "rate_multiplier" field.
|
|
func (_u *GroupUpdateOne) AddRateMultiplier(v float64) *GroupUpdateOne {
|
|
_u.mutation.AddRateMultiplier(v)
|
|
return _u
|
|
}
|
|
|
|
// SetIsExclusive sets the "is_exclusive" field.
|
|
func (_u *GroupUpdateOne) SetIsExclusive(v bool) *GroupUpdateOne {
|
|
_u.mutation.SetIsExclusive(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsExclusive sets the "is_exclusive" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableIsExclusive(v *bool) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetIsExclusive(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *GroupUpdateOne) SetStatus(v string) *GroupUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableStatus(v *string) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPlatform sets the "platform" field.
|
|
func (_u *GroupUpdateOne) SetPlatform(v string) *GroupUpdateOne {
|
|
_u.mutation.SetPlatform(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePlatform sets the "platform" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillablePlatform(v *string) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetPlatform(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSubscriptionType sets the "subscription_type" field.
|
|
func (_u *GroupUpdateOne) SetSubscriptionType(v string) *GroupUpdateOne {
|
|
_u.mutation.SetSubscriptionType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSubscriptionType sets the "subscription_type" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableSubscriptionType(v *string) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetSubscriptionType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDailyLimitUsd sets the "daily_limit_usd" field.
|
|
func (_u *GroupUpdateOne) SetDailyLimitUsd(v float64) *GroupUpdateOne {
|
|
_u.mutation.ResetDailyLimitUsd()
|
|
_u.mutation.SetDailyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableDailyLimitUsd(v *float64) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetDailyLimitUsd(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddDailyLimitUsd adds value to the "daily_limit_usd" field.
|
|
func (_u *GroupUpdateOne) AddDailyLimitUsd(v float64) *GroupUpdateOne {
|
|
_u.mutation.AddDailyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
|
|
func (_u *GroupUpdateOne) ClearDailyLimitUsd() *GroupUpdateOne {
|
|
_u.mutation.ClearDailyLimitUsd()
|
|
return _u
|
|
}
|
|
|
|
// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
|
|
func (_u *GroupUpdateOne) SetWeeklyLimitUsd(v float64) *GroupUpdateOne {
|
|
_u.mutation.ResetWeeklyLimitUsd()
|
|
_u.mutation.SetWeeklyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableWeeklyLimitUsd(v *float64) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetWeeklyLimitUsd(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
|
|
func (_u *GroupUpdateOne) AddWeeklyLimitUsd(v float64) *GroupUpdateOne {
|
|
_u.mutation.AddWeeklyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
|
|
func (_u *GroupUpdateOne) ClearWeeklyLimitUsd() *GroupUpdateOne {
|
|
_u.mutation.ClearWeeklyLimitUsd()
|
|
return _u
|
|
}
|
|
|
|
// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
|
|
func (_u *GroupUpdateOne) SetMonthlyLimitUsd(v float64) *GroupUpdateOne {
|
|
_u.mutation.ResetMonthlyLimitUsd()
|
|
_u.mutation.SetMonthlyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableMonthlyLimitUsd(v *float64) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetMonthlyLimitUsd(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
|
|
func (_u *GroupUpdateOne) AddMonthlyLimitUsd(v float64) *GroupUpdateOne {
|
|
_u.mutation.AddMonthlyLimitUsd(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
|
|
func (_u *GroupUpdateOne) ClearMonthlyLimitUsd() *GroupUpdateOne {
|
|
_u.mutation.ClearMonthlyLimitUsd()
|
|
return _u
|
|
}
|
|
|
|
// SetDefaultValidityDays sets the "default_validity_days" field.
|
|
func (_u *GroupUpdateOne) SetDefaultValidityDays(v int) *GroupUpdateOne {
|
|
_u.mutation.ResetDefaultValidityDays()
|
|
_u.mutation.SetDefaultValidityDays(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
|
|
func (_u *GroupUpdateOne) SetNillableDefaultValidityDays(v *int) *GroupUpdateOne {
|
|
if v != nil {
|
|
_u.SetDefaultValidityDays(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddDefaultValidityDays adds value to the "default_validity_days" field.
|
|
func (_u *GroupUpdateOne) AddDefaultValidityDays(v int) *GroupUpdateOne {
|
|
_u.mutation.AddDefaultValidityDays(v)
|
|
return _u
|
|
}
|
|
|
|
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
|
|
func (_u *GroupUpdateOne) AddAPIKeyIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.AddAPIKeyIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAPIKeys adds the "api_keys" edges to the APIKey entity.
|
|
func (_u *GroupUpdateOne) AddAPIKeys(v ...*APIKey) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAPIKeyIDs(ids...)
|
|
}
|
|
|
|
// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
|
|
func (_u *GroupUpdateOne) AddRedeemCodeIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.AddRedeemCodeIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
|
|
func (_u *GroupUpdateOne) AddRedeemCodes(v ...*RedeemCode) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddRedeemCodeIDs(ids...)
|
|
}
|
|
|
|
// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
|
|
func (_u *GroupUpdateOne) AddSubscriptionIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.AddSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
|
|
func (_u *GroupUpdateOne) AddSubscriptions(v ...*UserSubscription) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
|
|
func (_u *GroupUpdateOne) AddUsageLogIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.AddUsageLogIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
|
|
func (_u *GroupUpdateOne) AddUsageLogs(v ...*UsageLog) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddUsageLogIDs(ids...)
|
|
}
|
|
|
|
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
|
|
func (_u *GroupUpdateOne) AddAccountIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.AddAccountIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAccounts adds the "accounts" edges to the Account entity.
|
|
func (_u *GroupUpdateOne) AddAccounts(v ...*Account) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAccountIDs(ids...)
|
|
}
|
|
|
|
// AddAllowedUserIDs adds the "allowed_users" edge to the User entity by IDs.
|
|
func (_u *GroupUpdateOne) AddAllowedUserIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.AddAllowedUserIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddAllowedUsers adds the "allowed_users" edges to the User entity.
|
|
func (_u *GroupUpdateOne) AddAllowedUsers(v ...*User) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddAllowedUserIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the GroupMutation object of the builder.
|
|
func (_u *GroupUpdateOne) Mutation() *GroupMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearAPIKeys clears all "api_keys" edges to the APIKey entity.
|
|
func (_u *GroupUpdateOne) ClearAPIKeys() *GroupUpdateOne {
|
|
_u.mutation.ClearAPIKeys()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAPIKeyIDs removes the "api_keys" edge to APIKey entities by IDs.
|
|
func (_u *GroupUpdateOne) RemoveAPIKeyIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.RemoveAPIKeyIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAPIKeys removes "api_keys" edges to APIKey entities.
|
|
func (_u *GroupUpdateOne) RemoveAPIKeys(v ...*APIKey) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAPIKeyIDs(ids...)
|
|
}
|
|
|
|
// ClearRedeemCodes clears all "redeem_codes" edges to the RedeemCode entity.
|
|
func (_u *GroupUpdateOne) ClearRedeemCodes() *GroupUpdateOne {
|
|
_u.mutation.ClearRedeemCodes()
|
|
return _u
|
|
}
|
|
|
|
// RemoveRedeemCodeIDs removes the "redeem_codes" edge to RedeemCode entities by IDs.
|
|
func (_u *GroupUpdateOne) RemoveRedeemCodeIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.RemoveRedeemCodeIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveRedeemCodes removes "redeem_codes" edges to RedeemCode entities.
|
|
func (_u *GroupUpdateOne) RemoveRedeemCodes(v ...*RedeemCode) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveRedeemCodeIDs(ids...)
|
|
}
|
|
|
|
// ClearSubscriptions clears all "subscriptions" edges to the UserSubscription entity.
|
|
func (_u *GroupUpdateOne) ClearSubscriptions() *GroupUpdateOne {
|
|
_u.mutation.ClearSubscriptions()
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptionIDs removes the "subscriptions" edge to UserSubscription entities by IDs.
|
|
func (_u *GroupUpdateOne) RemoveSubscriptionIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.RemoveSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptions removes "subscriptions" edges to UserSubscription entities.
|
|
func (_u *GroupUpdateOne) RemoveSubscriptions(v ...*UserSubscription) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
|
|
func (_u *GroupUpdateOne) ClearUsageLogs() *GroupUpdateOne {
|
|
_u.mutation.ClearUsageLogs()
|
|
return _u
|
|
}
|
|
|
|
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
|
|
func (_u *GroupUpdateOne) RemoveUsageLogIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.RemoveUsageLogIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
|
|
func (_u *GroupUpdateOne) RemoveUsageLogs(v ...*UsageLog) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveUsageLogIDs(ids...)
|
|
}
|
|
|
|
// ClearAccounts clears all "accounts" edges to the Account entity.
|
|
func (_u *GroupUpdateOne) ClearAccounts() *GroupUpdateOne {
|
|
_u.mutation.ClearAccounts()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
|
|
func (_u *GroupUpdateOne) RemoveAccountIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.RemoveAccountIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAccounts removes "accounts" edges to Account entities.
|
|
func (_u *GroupUpdateOne) RemoveAccounts(v ...*Account) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAccountIDs(ids...)
|
|
}
|
|
|
|
// ClearAllowedUsers clears all "allowed_users" edges to the User entity.
|
|
func (_u *GroupUpdateOne) ClearAllowedUsers() *GroupUpdateOne {
|
|
_u.mutation.ClearAllowedUsers()
|
|
return _u
|
|
}
|
|
|
|
// RemoveAllowedUserIDs removes the "allowed_users" edge to User entities by IDs.
|
|
func (_u *GroupUpdateOne) RemoveAllowedUserIDs(ids ...int64) *GroupUpdateOne {
|
|
_u.mutation.RemoveAllowedUserIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveAllowedUsers removes "allowed_users" edges to User entities.
|
|
func (_u *GroupUpdateOne) RemoveAllowedUsers(v ...*User) *GroupUpdateOne {
|
|
ids := make([]int64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveAllowedUserIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the GroupUpdate builder.
|
|
func (_u *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne {
|
|
_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 *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Group entity.
|
|
func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
|
|
if err := _u.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *GroupUpdateOne) SaveX(ctx context.Context) *Group {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *GroupUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *GroupUpdateOne) 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 *GroupUpdateOne) defaults() error {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
if group.UpdateDefaultUpdatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized group.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := group.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *GroupUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := group.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Group.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := group.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Group.status": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Platform(); ok {
|
|
if err := group.PlatformValidator(v); err != nil {
|
|
return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "Group.platform": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.SubscriptionType(); ok {
|
|
if err := group.SubscriptionTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "subscription_type", err: fmt.Errorf(`ent: validator failed for field "Group.subscription_type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Group.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, group.FieldID)
|
|
for _, f := range fields {
|
|
if !group.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != group.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(group.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.DeletedAt(); ok {
|
|
_spec.SetField(group.FieldDeletedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DeletedAtCleared() {
|
|
_spec.ClearField(group.FieldDeletedAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(group.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(group.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(group.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.RateMultiplier(); ok {
|
|
_spec.SetField(group.FieldRateMultiplier, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedRateMultiplier(); ok {
|
|
_spec.AddField(group.FieldRateMultiplier, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.IsExclusive(); ok {
|
|
_spec.SetField(group.FieldIsExclusive, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(group.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Platform(); ok {
|
|
_spec.SetField(group.FieldPlatform, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.SubscriptionType(); ok {
|
|
_spec.SetField(group.FieldSubscriptionType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.DailyLimitUsd(); ok {
|
|
_spec.SetField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
|
|
_spec.AddField(group.FieldDailyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.DailyLimitUsdCleared() {
|
|
_spec.ClearField(group.FieldDailyLimitUsd, field.TypeFloat64)
|
|
}
|
|
if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
|
|
_spec.SetField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
|
|
_spec.AddField(group.FieldWeeklyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.WeeklyLimitUsdCleared() {
|
|
_spec.ClearField(group.FieldWeeklyLimitUsd, field.TypeFloat64)
|
|
}
|
|
if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
|
|
_spec.SetField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
|
|
_spec.AddField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
|
|
}
|
|
if _u.mutation.MonthlyLimitUsdCleared() {
|
|
_spec.ClearField(group.FieldMonthlyLimitUsd, field.TypeFloat64)
|
|
}
|
|
if value, ok := _u.mutation.DefaultValidityDays(); ok {
|
|
_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedDefaultValidityDays(); ok {
|
|
_spec.AddField(group.FieldDefaultValidityDays, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.APIKeysCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.APIKeysTable,
|
|
Columns: []string{group.APIKeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAPIKeysIDs(); len(nodes) > 0 && !_u.mutation.APIKeysCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.APIKeysTable,
|
|
Columns: []string{group.APIKeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.APIKeysIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.APIKeysTable,
|
|
Columns: []string{group.APIKeysColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.RedeemCodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.RedeemCodesTable,
|
|
Columns: []string{group.RedeemCodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedRedeemCodesIDs(); len(nodes) > 0 && !_u.mutation.RedeemCodesCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.RedeemCodesTable,
|
|
Columns: []string{group.RedeemCodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RedeemCodesIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.RedeemCodesTable,
|
|
Columns: []string{group.RedeemCodesColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.SubscriptionsTable,
|
|
Columns: []string{group.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.SubscriptionsTable,
|
|
Columns: []string{group.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.SubscriptionsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.SubscriptionsTable,
|
|
Columns: []string{group.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.UsageLogsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.UsageLogsTable,
|
|
Columns: []string{group.UsageLogsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.UsageLogsTable,
|
|
Columns: []string{group.UsageLogsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: group.UsageLogsTable,
|
|
Columns: []string{group.UsageLogsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.AccountsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AccountsTable,
|
|
Columns: group.AccountsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AccountsTable,
|
|
Columns: group.AccountsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AccountsTable,
|
|
Columns: group.AccountsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &AccountGroupCreate{config: _u.config, mutation: newAccountGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.AllowedUsersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AllowedUsersTable,
|
|
Columns: group.AllowedUsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedAllowedUsersIDs(); len(nodes) > 0 && !_u.mutation.AllowedUsersCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AllowedUsersTable,
|
|
Columns: group.AllowedUsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.AllowedUsersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: group.AllowedUsersTable,
|
|
Columns: group.AllowedUsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
createE := &UserAllowedGroupCreate{config: _u.config, mutation: newUserAllowedGroupMutation(_u.config, OpCreate)}
|
|
createE.defaults()
|
|
_, specE := createE.createSpec()
|
|
edge.Target.Fields = specE.Fields
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &Group{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{group.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|