Files
yokowu c30c73aa93 feat: 添加 Host/VM ent schema 和数据库迁移
- ent/schema: host, virtualmachine, teamhost, teamgrouphost
- 修改 user/team/teamgroup/model schema 添加 host/vm edges
- migration/000003: hosts, virtualmachines, team_hosts, team_group_hosts 建表
2026-03-17 14:38:26 +08:00

178 lines
5.6 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/team"
"github.com/chaitin/MonkeyCode/backend/db/teamhost"
"github.com/google/uuid"
)
// TeamHost is the model entity for the TeamHost schema.
type TeamHost struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// TeamID holds the value of the "team_id" field.
TeamID uuid.UUID `json:"team_id,omitempty"`
// HostID holds the value of the "host_id" field.
HostID string `json:"host_id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the TeamHostQuery when eager-loading is set.
Edges TeamHostEdges `json:"edges"`
selectValues sql.SelectValues
}
// TeamHostEdges holds the relations/edges for other nodes in the graph.
type TeamHostEdges struct {
// Team holds the value of the team edge.
Team *Team `json:"team,omitempty"`
// Host holds the value of the host edge.
Host *Host `json:"host,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// TeamOrErr returns the Team value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TeamHostEdges) TeamOrErr() (*Team, error) {
if e.Team != nil {
return e.Team, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: team.Label}
}
return nil, &NotLoadedError{edge: "team"}
}
// HostOrErr returns the Host value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TeamHostEdges) HostOrErr() (*Host, error) {
if e.Host != nil {
return e.Host, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: host.Label}
}
return nil, &NotLoadedError{edge: "host"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*TeamHost) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case teamhost.FieldHostID:
values[i] = new(sql.NullString)
case teamhost.FieldCreatedAt:
values[i] = new(sql.NullTime)
case teamhost.FieldID, teamhost.FieldTeamID:
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 TeamHost fields.
func (_m *TeamHost) 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 teamhost.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
_m.ID = *value
}
case teamhost.FieldTeamID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field team_id", values[i])
} else if value != nil {
_m.TeamID = *value
}
case teamhost.FieldHostID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field host_id", values[i])
} else if value.Valid {
_m.HostID = value.String
}
case teamhost.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
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the TeamHost.
// This includes values selected through modifiers, order, etc.
func (_m *TeamHost) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryTeam queries the "team" edge of the TeamHost entity.
func (_m *TeamHost) QueryTeam() *TeamQuery {
return NewTeamHostClient(_m.config).QueryTeam(_m)
}
// QueryHost queries the "host" edge of the TeamHost entity.
func (_m *TeamHost) QueryHost() *HostQuery {
return NewTeamHostClient(_m.config).QueryHost(_m)
}
// Update returns a builder for updating this TeamHost.
// Note that you need to call TeamHost.Unwrap() before calling this method if this TeamHost
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *TeamHost) Update() *TeamHostUpdateOne {
return NewTeamHostClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the TeamHost 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 *TeamHost) Unwrap() *TeamHost {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: TeamHost is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *TeamHost) String() string {
var builder strings.Builder
builder.WriteString("TeamHost(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("team_id=")
builder.WriteString(fmt.Sprintf("%v", _m.TeamID))
builder.WriteString(", ")
builder.WriteString("host_id=")
builder.WriteString(_m.HostID)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// TeamHosts is a parsable slice of TeamHost.
type TeamHosts []*TeamHost