mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
- ent/schema: host, virtualmachine, teamhost, teamgrouphost - 修改 user/team/teamgroup/model schema 添加 host/vm edges - migration/000003: hosts, virtualmachines, team_hosts, team_group_hosts 建表
474 lines
13 KiB
Go
474 lines
13 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/host"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/chaitin/MonkeyCode/backend/db/team"
|
|
"github.com/chaitin/MonkeyCode/backend/db/teamhost"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// TeamHostUpdate is the builder for updating TeamHost entities.
|
|
type TeamHostUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *TeamHostMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the TeamHostUpdate builder.
|
|
func (_u *TeamHostUpdate) Where(ps ...predicate.TeamHost) *TeamHostUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (_u *TeamHostUpdate) SetTeamID(v uuid.UUID) *TeamHostUpdate {
|
|
_u.mutation.SetTeamID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTeamID sets the "team_id" field if the given value is not nil.
|
|
func (_u *TeamHostUpdate) SetNillableTeamID(v *uuid.UUID) *TeamHostUpdate {
|
|
if v != nil {
|
|
_u.SetTeamID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetHostID sets the "host_id" field.
|
|
func (_u *TeamHostUpdate) SetHostID(v string) *TeamHostUpdate {
|
|
_u.mutation.SetHostID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableHostID sets the "host_id" field if the given value is not nil.
|
|
func (_u *TeamHostUpdate) SetNillableHostID(v *string) *TeamHostUpdate {
|
|
if v != nil {
|
|
_u.SetHostID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *TeamHostUpdate) SetCreatedAt(v time.Time) *TeamHostUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *TeamHostUpdate) SetNillableCreatedAt(v *time.Time) *TeamHostUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTeam sets the "team" edge to the Team entity.
|
|
func (_u *TeamHostUpdate) SetTeam(v *Team) *TeamHostUpdate {
|
|
return _u.SetTeamID(v.ID)
|
|
}
|
|
|
|
// SetHost sets the "host" edge to the Host entity.
|
|
func (_u *TeamHostUpdate) SetHost(v *Host) *TeamHostUpdate {
|
|
return _u.SetHostID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the TeamHostMutation object of the builder.
|
|
func (_u *TeamHostUpdate) Mutation() *TeamHostMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearTeam clears the "team" edge to the Team entity.
|
|
func (_u *TeamHostUpdate) ClearTeam() *TeamHostUpdate {
|
|
_u.mutation.ClearTeam()
|
|
return _u
|
|
}
|
|
|
|
// ClearHost clears the "host" edge to the Host entity.
|
|
func (_u *TeamHostUpdate) ClearHost() *TeamHostUpdate {
|
|
_u.mutation.ClearHost()
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *TeamHostUpdate) 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 *TeamHostUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *TeamHostUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *TeamHostUpdate) 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 *TeamHostUpdate) check() error {
|
|
if _u.mutation.TeamCleared() && len(_u.mutation.TeamIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "TeamHost.team"`)
|
|
}
|
|
if _u.mutation.HostCleared() && len(_u.mutation.HostIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "TeamHost.host"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *TeamHostUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamHostUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *TeamHostUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(teamhost.Table, teamhost.Columns, sqlgraph.NewFieldSpec(teamhost.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(teamhost.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.TeamCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.TeamTable,
|
|
Columns: []string{teamhost.TeamColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.TeamIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.TeamTable,
|
|
Columns: []string{teamhost.TeamColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.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.HostCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.HostTable,
|
|
Columns: []string{teamhost.HostColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(host.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.HostIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.HostTable,
|
|
Columns: []string{teamhost.HostColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(host.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
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{teamhost.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// TeamHostUpdateOne is the builder for updating a single TeamHost entity.
|
|
type TeamHostUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *TeamHostMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetTeamID sets the "team_id" field.
|
|
func (_u *TeamHostUpdateOne) SetTeamID(v uuid.UUID) *TeamHostUpdateOne {
|
|
_u.mutation.SetTeamID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTeamID sets the "team_id" field if the given value is not nil.
|
|
func (_u *TeamHostUpdateOne) SetNillableTeamID(v *uuid.UUID) *TeamHostUpdateOne {
|
|
if v != nil {
|
|
_u.SetTeamID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetHostID sets the "host_id" field.
|
|
func (_u *TeamHostUpdateOne) SetHostID(v string) *TeamHostUpdateOne {
|
|
_u.mutation.SetHostID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableHostID sets the "host_id" field if the given value is not nil.
|
|
func (_u *TeamHostUpdateOne) SetNillableHostID(v *string) *TeamHostUpdateOne {
|
|
if v != nil {
|
|
_u.SetHostID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *TeamHostUpdateOne) SetCreatedAt(v time.Time) *TeamHostUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *TeamHostUpdateOne) SetNillableCreatedAt(v *time.Time) *TeamHostUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTeam sets the "team" edge to the Team entity.
|
|
func (_u *TeamHostUpdateOne) SetTeam(v *Team) *TeamHostUpdateOne {
|
|
return _u.SetTeamID(v.ID)
|
|
}
|
|
|
|
// SetHost sets the "host" edge to the Host entity.
|
|
func (_u *TeamHostUpdateOne) SetHost(v *Host) *TeamHostUpdateOne {
|
|
return _u.SetHostID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the TeamHostMutation object of the builder.
|
|
func (_u *TeamHostUpdateOne) Mutation() *TeamHostMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearTeam clears the "team" edge to the Team entity.
|
|
func (_u *TeamHostUpdateOne) ClearTeam() *TeamHostUpdateOne {
|
|
_u.mutation.ClearTeam()
|
|
return _u
|
|
}
|
|
|
|
// ClearHost clears the "host" edge to the Host entity.
|
|
func (_u *TeamHostUpdateOne) ClearHost() *TeamHostUpdateOne {
|
|
_u.mutation.ClearHost()
|
|
return _u
|
|
}
|
|
|
|
// Where appends a list predicates to the TeamHostUpdate builder.
|
|
func (_u *TeamHostUpdateOne) Where(ps ...predicate.TeamHost) *TeamHostUpdateOne {
|
|
_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 *TeamHostUpdateOne) Select(field string, fields ...string) *TeamHostUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated TeamHost entity.
|
|
func (_u *TeamHostUpdateOne) Save(ctx context.Context) (*TeamHost, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *TeamHostUpdateOne) SaveX(ctx context.Context) *TeamHost {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *TeamHostUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *TeamHostUpdateOne) 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 *TeamHostUpdateOne) check() error {
|
|
if _u.mutation.TeamCleared() && len(_u.mutation.TeamIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "TeamHost.team"`)
|
|
}
|
|
if _u.mutation.HostCleared() && len(_u.mutation.HostIDs()) > 0 {
|
|
return errors.New(`db: clearing a required unique edge "TeamHost.host"`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *TeamHostUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *TeamHostUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *TeamHostUpdateOne) sqlSave(ctx context.Context) (_node *TeamHost, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(teamhost.Table, teamhost.Columns, sqlgraph.NewFieldSpec(teamhost.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "TeamHost.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, teamhost.FieldID)
|
|
for _, f := range fields {
|
|
if !teamhost.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != teamhost.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(teamhost.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.TeamCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.TeamTable,
|
|
Columns: []string{teamhost.TeamColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.TeamIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.TeamTable,
|
|
Columns: []string{teamhost.TeamColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(team.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.HostCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.HostTable,
|
|
Columns: []string{teamhost.HostColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(host.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.HostIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: teamhost.HostTable,
|
|
Columns: []string{teamhost.HostColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(host.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
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 = &TeamHost{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{teamhost.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|