mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 03:18:50 +08:00
- 新增 git_bots, git_bot_users, git_bot_tasks, project_git_bots 表 - 添加 user, host, project 到 gitbot 的关联边 - 使用 soft delete 和 created_at 游标
474 lines
14 KiB
Go
474 lines
14 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/chaitin/MonkeyCode/backend/db/gitbot"
|
|
"github.com/chaitin/MonkeyCode/backend/db/gitbotuser"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// GitBotUserUpdate is the builder for updating GitBotUser entities.
|
|
type GitBotUserUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *GitBotUserMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the GitBotUserUpdate builder.
|
|
func (_u *GitBotUserUpdate) Where(ps ...predicate.GitBotUser) *GitBotUserUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetGitBotID sets the "git_bot_id" field.
|
|
func (_u *GitBotUserUpdate) SetGitBotID(v uuid.UUID) *GitBotUserUpdate {
|
|
_u.mutation.SetGitBotID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableGitBotID sets the "git_bot_id" field if the given value is not nil.
|
|
func (_u *GitBotUserUpdate) SetNillableGitBotID(v *uuid.UUID) *GitBotUserUpdate {
|
|
if v != nil {
|
|
_u.SetGitBotID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_u *GitBotUserUpdate) SetUserID(v uuid.UUID) *GitBotUserUpdate {
|
|
_u.mutation.SetUserID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (_u *GitBotUserUpdate) SetNillableUserID(v *uuid.UUID) *GitBotUserUpdate {
|
|
if v != nil {
|
|
_u.SetUserID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *GitBotUserUpdate) SetCreatedAt(v time.Time) *GitBotUserUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *GitBotUserUpdate) SetNillableCreatedAt(v *time.Time) *GitBotUserUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetGitBot sets the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotUserUpdate) SetGitBot(v *GitBot) *GitBotUserUpdate {
|
|
return _u.SetGitBotID(v.ID)
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_u *GitBotUserUpdate) SetUser(v *User) *GitBotUserUpdate {
|
|
return _u.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the GitBotUserMutation object of the builder.
|
|
func (_u *GitBotUserUpdate) Mutation() *GitBotUserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearGitBot clears the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotUserUpdate) ClearGitBot() *GitBotUserUpdate {
|
|
_u.mutation.ClearGitBot()
|
|
return _u
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (_u *GitBotUserUpdate) ClearUser() *GitBotUserUpdate {
|
|
_u.mutation.ClearUser()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *GitBotUserUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *GitBotUserUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *GitBotUserUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *GitBotUserUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *GitBotUserUpdate) check() error {
|
|
if _u.mutation.GitBotCleared() && len(_u.mutation.GitBotIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotUser.git_bot"`)
|
|
}
|
|
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotUser.user"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *GitBotUserUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GitBotUserUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *GitBotUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(gitbotuser.Table, gitbotuser.Columns, sqlgraph.NewFieldSpec(gitbotuser.FieldID, field.TypeUUID))
|
|
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.CreatedAt(); ok {
|
|
_spec.SetField(gitbotuser.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.GitBotCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.GitBotTable,
|
|
Columns: []string{gitbotuser.GitBotColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.GitBotIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.GitBotTable,
|
|
Columns: []string{gitbotuser.GitBotColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.UserTable,
|
|
Columns: []string{gitbotuser.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.UserTable,
|
|
Columns: []string{gitbotuser.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{gitbotuser.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// GitBotUserUpdateOne is the builder for updating a single GitBotUser entity.
|
|
type GitBotUserUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *GitBotUserMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetGitBotID sets the "git_bot_id" field.
|
|
func (_u *GitBotUserUpdateOne) SetGitBotID(v uuid.UUID) *GitBotUserUpdateOne {
|
|
_u.mutation.SetGitBotID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableGitBotID sets the "git_bot_id" field if the given value is not nil.
|
|
func (_u *GitBotUserUpdateOne) SetNillableGitBotID(v *uuid.UUID) *GitBotUserUpdateOne {
|
|
if v != nil {
|
|
_u.SetGitBotID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_u *GitBotUserUpdateOne) SetUserID(v uuid.UUID) *GitBotUserUpdateOne {
|
|
_u.mutation.SetUserID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (_u *GitBotUserUpdateOne) SetNillableUserID(v *uuid.UUID) *GitBotUserUpdateOne {
|
|
if v != nil {
|
|
_u.SetUserID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *GitBotUserUpdateOne) SetCreatedAt(v time.Time) *GitBotUserUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *GitBotUserUpdateOne) SetNillableCreatedAt(v *time.Time) *GitBotUserUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetGitBot sets the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotUserUpdateOne) SetGitBot(v *GitBot) *GitBotUserUpdateOne {
|
|
return _u.SetGitBotID(v.ID)
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (_u *GitBotUserUpdateOne) SetUser(v *User) *GitBotUserUpdateOne {
|
|
return _u.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the GitBotUserMutation object of the builder.
|
|
func (_u *GitBotUserUpdateOne) Mutation() *GitBotUserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearGitBot clears the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotUserUpdateOne) ClearGitBot() *GitBotUserUpdateOne {
|
|
_u.mutation.ClearGitBot()
|
|
return _u
|
|
}
|
|
|
|
// ClearUser clears the "user" edge to the User entity.
|
|
func (_u *GitBotUserUpdateOne) ClearUser() *GitBotUserUpdateOne {
|
|
_u.mutation.ClearUser()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the GitBotUserUpdate builder.
|
|
func (_u *GitBotUserUpdateOne) Where(ps ...predicate.GitBotUser) *GitBotUserUpdateOne {
|
|
_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 *GitBotUserUpdateOne) Select(field string, fields ...string) *GitBotUserUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated GitBotUser entity.
|
|
func (_u *GitBotUserUpdateOne) Save(ctx context.Context) (*GitBotUser, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *GitBotUserUpdateOne) SaveX(ctx context.Context) *GitBotUser {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *GitBotUserUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *GitBotUserUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *GitBotUserUpdateOne) check() error {
|
|
if _u.mutation.GitBotCleared() && len(_u.mutation.GitBotIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotUser.git_bot"`)
|
|
}
|
|
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotUser.user"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *GitBotUserUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GitBotUserUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *GitBotUserUpdateOne) sqlSave(ctx context.Context) (_node *GitBotUser, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(gitbotuser.Table, gitbotuser.Columns, sqlgraph.NewFieldSpec(gitbotuser.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "GitBotUser.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, gitbotuser.FieldID)
|
|
for _, f := range fields {
|
|
if !gitbotuser.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != gitbotuser.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.CreatedAt(); ok {
|
|
_spec.SetField(gitbotuser.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.GitBotCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.GitBotTable,
|
|
Columns: []string{gitbotuser.GitBotColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.GitBotIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.GitBotTable,
|
|
Columns: []string{gitbotuser.GitBotColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(gitbot.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.UserCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.UserTable,
|
|
Columns: []string{gitbotuser.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: gitbotuser.UserTable,
|
|
Columns: []string{gitbotuser.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &GitBotUser{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{gitbotuser.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|