mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-22 19:39:31 +08:00
- 新增 git_bots, git_bot_users, git_bot_tasks, project_git_bots 表 - 添加 user, host, project 到 gitbot 的关联边 - 使用 soft delete 和 created_at 游标
368 lines
12 KiB
Go
368 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/chaitin/MonkeyCode/backend/db/host"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Host is the model entity for the Host schema.
|
|
type Host struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID string `json:"id,omitempty"`
|
|
// DeletedAt holds the value of the "deleted_at" field.
|
|
DeletedAt time.Time `json:"deleted_at,omitempty"`
|
|
// UserID holds the value of the "user_id" field.
|
|
UserID uuid.UUID `json:"user_id,omitempty"`
|
|
// Hostname holds the value of the "hostname" field.
|
|
Hostname string `json:"hostname,omitempty"`
|
|
// Arch holds the value of the "arch" field.
|
|
Arch string `json:"arch,omitempty"`
|
|
// Cores holds the value of the "cores" field.
|
|
Cores int `json:"cores,omitempty"`
|
|
// Weight holds the value of the "weight" field.
|
|
Weight int `json:"weight,omitempty"`
|
|
// Memory holds the value of the "memory" field.
|
|
Memory int64 `json:"memory,omitempty"`
|
|
// Disk holds the value of the "disk" field.
|
|
Disk int64 `json:"disk,omitempty"`
|
|
// Os holds the value of the "os" field.
|
|
Os string `json:"os,omitempty"`
|
|
// ExternalIP holds the value of the "external_ip" field.
|
|
ExternalIP string `json:"external_ip,omitempty"`
|
|
// InternalIP holds the value of the "internal_ip" field.
|
|
InternalIP string `json:"internal_ip,omitempty"`
|
|
// Version holds the value of the "version" field.
|
|
Version string `json:"version,omitempty"`
|
|
// MachineID holds the value of the "machine_id" field.
|
|
MachineID string `json:"machine_id,omitempty"`
|
|
// Remark holds the value of the "remark" field.
|
|
Remark string `json:"remark,omitempty"`
|
|
// CreatedAt holds the value of the "created_at" field.
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the HostQuery when eager-loading is set.
|
|
Edges HostEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// HostEdges holds the relations/edges for other nodes in the graph.
|
|
type HostEdges struct {
|
|
// Vms holds the value of the vms edge.
|
|
Vms []*VirtualMachine `json:"vms,omitempty"`
|
|
// User holds the value of the user edge.
|
|
User *User `json:"user,omitempty"`
|
|
// Groups holds the value of the groups edge.
|
|
Groups []*TeamGroup `json:"groups,omitempty"`
|
|
// GitBots holds the value of the git_bots edge.
|
|
GitBots []*GitBot `json:"git_bots,omitempty"`
|
|
// TeamGroupHosts holds the value of the team_group_hosts edge.
|
|
TeamGroupHosts []*TeamGroupHost `json:"team_group_hosts,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [5]bool
|
|
}
|
|
|
|
// VmsOrErr returns the Vms value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e HostEdges) VmsOrErr() ([]*VirtualMachine, error) {
|
|
if e.loadedTypes[0] {
|
|
return e.Vms, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "vms"}
|
|
}
|
|
|
|
// UserOrErr returns the User value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e HostEdges) UserOrErr() (*User, error) {
|
|
if e.User != nil {
|
|
return e.User, nil
|
|
} else if e.loadedTypes[1] {
|
|
return nil, &NotFoundError{label: user.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "user"}
|
|
}
|
|
|
|
// GroupsOrErr returns the Groups value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e HostEdges) GroupsOrErr() ([]*TeamGroup, error) {
|
|
if e.loadedTypes[2] {
|
|
return e.Groups, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "groups"}
|
|
}
|
|
|
|
// GitBotsOrErr returns the GitBots value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e HostEdges) GitBotsOrErr() ([]*GitBot, error) {
|
|
if e.loadedTypes[3] {
|
|
return e.GitBots, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "git_bots"}
|
|
}
|
|
|
|
// TeamGroupHostsOrErr returns the TeamGroupHosts value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e HostEdges) TeamGroupHostsOrErr() ([]*TeamGroupHost, error) {
|
|
if e.loadedTypes[4] {
|
|
return e.TeamGroupHosts, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "team_group_hosts"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Host) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case host.FieldCores, host.FieldWeight, host.FieldMemory, host.FieldDisk:
|
|
values[i] = new(sql.NullInt64)
|
|
case host.FieldID, host.FieldHostname, host.FieldArch, host.FieldOs, host.FieldExternalIP, host.FieldInternalIP, host.FieldVersion, host.FieldMachineID, host.FieldRemark:
|
|
values[i] = new(sql.NullString)
|
|
case host.FieldDeletedAt, host.FieldCreatedAt, host.FieldUpdatedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case host.FieldUserID:
|
|
values[i] = new(uuid.UUID)
|
|
default:
|
|
values[i] = new(sql.UnknownType)
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
// to the Host fields.
|
|
func (_m *Host) assignValues(columns []string, values []any) error {
|
|
if m, n := len(values), len(columns); m < n {
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
}
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case host.FieldID:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
|
} else if value.Valid {
|
|
_m.ID = value.String
|
|
}
|
|
case host.FieldDeletedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
|
} else if value.Valid {
|
|
_m.DeletedAt = value.Time
|
|
}
|
|
case host.FieldUserID:
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
|
} else if value != nil {
|
|
_m.UserID = *value
|
|
}
|
|
case host.FieldHostname:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field hostname", values[i])
|
|
} else if value.Valid {
|
|
_m.Hostname = value.String
|
|
}
|
|
case host.FieldArch:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field arch", values[i])
|
|
} else if value.Valid {
|
|
_m.Arch = value.String
|
|
}
|
|
case host.FieldCores:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field cores", values[i])
|
|
} else if value.Valid {
|
|
_m.Cores = int(value.Int64)
|
|
}
|
|
case host.FieldWeight:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field weight", values[i])
|
|
} else if value.Valid {
|
|
_m.Weight = int(value.Int64)
|
|
}
|
|
case host.FieldMemory:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field memory", values[i])
|
|
} else if value.Valid {
|
|
_m.Memory = value.Int64
|
|
}
|
|
case host.FieldDisk:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field disk", values[i])
|
|
} else if value.Valid {
|
|
_m.Disk = value.Int64
|
|
}
|
|
case host.FieldOs:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field os", values[i])
|
|
} else if value.Valid {
|
|
_m.Os = value.String
|
|
}
|
|
case host.FieldExternalIP:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field external_ip", values[i])
|
|
} else if value.Valid {
|
|
_m.ExternalIP = value.String
|
|
}
|
|
case host.FieldInternalIP:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field internal_ip", values[i])
|
|
} else if value.Valid {
|
|
_m.InternalIP = value.String
|
|
}
|
|
case host.FieldVersion:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field version", values[i])
|
|
} else if value.Valid {
|
|
_m.Version = value.String
|
|
}
|
|
case host.FieldMachineID:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field machine_id", values[i])
|
|
} else if value.Valid {
|
|
_m.MachineID = value.String
|
|
}
|
|
case host.FieldRemark:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field remark", values[i])
|
|
} else if value.Valid {
|
|
_m.Remark = value.String
|
|
}
|
|
case host.FieldCreatedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
|
} else if value.Valid {
|
|
_m.CreatedAt = value.Time
|
|
}
|
|
case host.FieldUpdatedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
} else if value.Valid {
|
|
_m.UpdatedAt = value.Time
|
|
}
|
|
default:
|
|
_m.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the Host.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *Host) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryVms queries the "vms" edge of the Host entity.
|
|
func (_m *Host) QueryVms() *VirtualMachineQuery {
|
|
return NewHostClient(_m.config).QueryVms(_m)
|
|
}
|
|
|
|
// QueryUser queries the "user" edge of the Host entity.
|
|
func (_m *Host) QueryUser() *UserQuery {
|
|
return NewHostClient(_m.config).QueryUser(_m)
|
|
}
|
|
|
|
// QueryGroups queries the "groups" edge of the Host entity.
|
|
func (_m *Host) QueryGroups() *TeamGroupQuery {
|
|
return NewHostClient(_m.config).QueryGroups(_m)
|
|
}
|
|
|
|
// QueryGitBots queries the "git_bots" edge of the Host entity.
|
|
func (_m *Host) QueryGitBots() *GitBotQuery {
|
|
return NewHostClient(_m.config).QueryGitBots(_m)
|
|
}
|
|
|
|
// QueryTeamGroupHosts queries the "team_group_hosts" edge of the Host entity.
|
|
func (_m *Host) QueryTeamGroupHosts() *TeamGroupHostQuery {
|
|
return NewHostClient(_m.config).QueryTeamGroupHosts(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this Host.
|
|
// Note that you need to call Host.Unwrap() before calling this method if this Host
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *Host) Update() *HostUpdateOne {
|
|
return NewHostClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the Host entity that was returned from a transaction after it was closed,
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
|
func (_m *Host) Unwrap() *Host {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: Host is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *Host) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Host(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
|
builder.WriteString("deleted_at=")
|
|
builder.WriteString(_m.DeletedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("user_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("hostname=")
|
|
builder.WriteString(_m.Hostname)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("arch=")
|
|
builder.WriteString(_m.Arch)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("cores=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Cores))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("weight=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Weight))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("memory=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Memory))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("disk=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Disk))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("os=")
|
|
builder.WriteString(_m.Os)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("external_ip=")
|
|
builder.WriteString(_m.ExternalIP)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("internal_ip=")
|
|
builder.WriteString(_m.InternalIP)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("version=")
|
|
builder.WriteString(_m.Version)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("machine_id=")
|
|
builder.WriteString(_m.MachineID)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("remark=")
|
|
builder.WriteString(_m.Remark)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("created_at=")
|
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("updated_at=")
|
|
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Hosts is a parsable slice of Host.
|
|
type Hosts []*Host
|