mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 11:28:46 +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/gitbottask"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/chaitin/MonkeyCode/backend/db/task"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// GitBotTaskUpdate is the builder for updating GitBotTask entities.
|
|
type GitBotTaskUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *GitBotTaskMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the GitBotTaskUpdate builder.
|
|
func (_u *GitBotTaskUpdate) Where(ps ...predicate.GitBotTask) *GitBotTaskUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetGitBotID sets the "git_bot_id" field.
|
|
func (_u *GitBotTaskUpdate) SetGitBotID(v uuid.UUID) *GitBotTaskUpdate {
|
|
_u.mutation.SetGitBotID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableGitBotID sets the "git_bot_id" field if the given value is not nil.
|
|
func (_u *GitBotTaskUpdate) SetNillableGitBotID(v *uuid.UUID) *GitBotTaskUpdate {
|
|
if v != nil {
|
|
_u.SetGitBotID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (_u *GitBotTaskUpdate) SetTaskID(v uuid.UUID) *GitBotTaskUpdate {
|
|
_u.mutation.SetTaskID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (_u *GitBotTaskUpdate) SetNillableTaskID(v *uuid.UUID) *GitBotTaskUpdate {
|
|
if v != nil {
|
|
_u.SetTaskID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *GitBotTaskUpdate) SetCreatedAt(v time.Time) *GitBotTaskUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *GitBotTaskUpdate) SetNillableCreatedAt(v *time.Time) *GitBotTaskUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTask sets the "task" edge to the Task entity.
|
|
func (_u *GitBotTaskUpdate) SetTask(v *Task) *GitBotTaskUpdate {
|
|
return _u.SetTaskID(v.ID)
|
|
}
|
|
|
|
// SetGitBot sets the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotTaskUpdate) SetGitBot(v *GitBot) *GitBotTaskUpdate {
|
|
return _u.SetGitBotID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the GitBotTaskMutation object of the builder.
|
|
func (_u *GitBotTaskUpdate) Mutation() *GitBotTaskMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearTask clears the "task" edge to the Task entity.
|
|
func (_u *GitBotTaskUpdate) ClearTask() *GitBotTaskUpdate {
|
|
_u.mutation.ClearTask()
|
|
return _u
|
|
}
|
|
|
|
// ClearGitBot clears the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotTaskUpdate) ClearGitBot() *GitBotTaskUpdate {
|
|
_u.mutation.ClearGitBot()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *GitBotTaskUpdate) 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 *GitBotTaskUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *GitBotTaskUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *GitBotTaskUpdate) 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 *GitBotTaskUpdate) check() error {
|
|
if _u.mutation.TaskCleared() && len(_u.mutation.TaskIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotTask.task"`)
|
|
}
|
|
if _u.mutation.GitBotCleared() && len(_u.mutation.GitBotIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotTask.git_bot"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *GitBotTaskUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GitBotTaskUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *GitBotTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(gitbottask.Table, gitbottask.Columns, sqlgraph.NewFieldSpec(gitbottask.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(gitbottask.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.TaskCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: gitbottask.TaskTable,
|
|
Columns: []string{gitbottask.TaskColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.TaskIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: gitbottask.TaskTable,
|
|
Columns: []string{gitbottask.TaskColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(task.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.GitBotCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: gitbottask.GitBotTable,
|
|
Columns: []string{gitbottask.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: true,
|
|
Table: gitbottask.GitBotTable,
|
|
Columns: []string{gitbottask.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)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{gitbottask.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// GitBotTaskUpdateOne is the builder for updating a single GitBotTask entity.
|
|
type GitBotTaskUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *GitBotTaskMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetGitBotID sets the "git_bot_id" field.
|
|
func (_u *GitBotTaskUpdateOne) SetGitBotID(v uuid.UUID) *GitBotTaskUpdateOne {
|
|
_u.mutation.SetGitBotID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableGitBotID sets the "git_bot_id" field if the given value is not nil.
|
|
func (_u *GitBotTaskUpdateOne) SetNillableGitBotID(v *uuid.UUID) *GitBotTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetGitBotID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (_u *GitBotTaskUpdateOne) SetTaskID(v uuid.UUID) *GitBotTaskUpdateOne {
|
|
_u.mutation.SetTaskID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (_u *GitBotTaskUpdateOne) SetNillableTaskID(v *uuid.UUID) *GitBotTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetTaskID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *GitBotTaskUpdateOne) SetCreatedAt(v time.Time) *GitBotTaskUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *GitBotTaskUpdateOne) SetNillableCreatedAt(v *time.Time) *GitBotTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTask sets the "task" edge to the Task entity.
|
|
func (_u *GitBotTaskUpdateOne) SetTask(v *Task) *GitBotTaskUpdateOne {
|
|
return _u.SetTaskID(v.ID)
|
|
}
|
|
|
|
// SetGitBot sets the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotTaskUpdateOne) SetGitBot(v *GitBot) *GitBotTaskUpdateOne {
|
|
return _u.SetGitBotID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the GitBotTaskMutation object of the builder.
|
|
func (_u *GitBotTaskUpdateOne) Mutation() *GitBotTaskMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearTask clears the "task" edge to the Task entity.
|
|
func (_u *GitBotTaskUpdateOne) ClearTask() *GitBotTaskUpdateOne {
|
|
_u.mutation.ClearTask()
|
|
return _u
|
|
}
|
|
|
|
// ClearGitBot clears the "git_bot" edge to the GitBot entity.
|
|
func (_u *GitBotTaskUpdateOne) ClearGitBot() *GitBotTaskUpdateOne {
|
|
_u.mutation.ClearGitBot()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the GitBotTaskUpdate builder.
|
|
func (_u *GitBotTaskUpdateOne) Where(ps ...predicate.GitBotTask) *GitBotTaskUpdateOne {
|
|
_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 *GitBotTaskUpdateOne) Select(field string, fields ...string) *GitBotTaskUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated GitBotTask entity.
|
|
func (_u *GitBotTaskUpdateOne) Save(ctx context.Context) (*GitBotTask, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *GitBotTaskUpdateOne) SaveX(ctx context.Context) *GitBotTask {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *GitBotTaskUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *GitBotTaskUpdateOne) 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 *GitBotTaskUpdateOne) check() error {
|
|
if _u.mutation.TaskCleared() && len(_u.mutation.TaskIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotTask.task"`)
|
|
}
|
|
if _u.mutation.GitBotCleared() && len(_u.mutation.GitBotIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "GitBotTask.git_bot"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *GitBotTaskUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GitBotTaskUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *GitBotTaskUpdateOne) sqlSave(ctx context.Context) (_node *GitBotTask, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(gitbottask.Table, gitbottask.Columns, sqlgraph.NewFieldSpec(gitbottask.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "GitBotTask.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, gitbottask.FieldID)
|
|
for _, f := range fields {
|
|
if !gitbottask.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != gitbottask.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(gitbottask.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.TaskCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: gitbottask.TaskTable,
|
|
Columns: []string{gitbottask.TaskColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.TaskIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: gitbottask.TaskTable,
|
|
Columns: []string{gitbottask.TaskColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(task.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.GitBotCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: gitbottask.GitBotTable,
|
|
Columns: []string{gitbottask.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: true,
|
|
Table: gitbottask.GitBotTable,
|
|
Columns: []string{gitbottask.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)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &GitBotTask{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{gitbottask.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|