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 游标
301 lines
10 KiB
Go
301 lines
10 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/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/task"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Task is the model entity for the Task schema.
|
|
type Task struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID uuid.UUID `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"`
|
|
// Kind holds the value of the "kind" field.
|
|
Kind consts.TaskType `json:"kind,omitempty"`
|
|
// SubType holds the value of the "sub_type" field.
|
|
SubType consts.TaskSubType `json:"sub_type,omitempty"`
|
|
// Content holds the value of the "content" field.
|
|
Content string `json:"content,omitempty"`
|
|
// Summary holds the value of the "summary" field.
|
|
Summary string `json:"summary,omitempty"`
|
|
// Status holds the value of the "status" field.
|
|
Status consts.TaskStatus `json:"status,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"`
|
|
// CompletedAt holds the value of the "completed_at" field.
|
|
CompletedAt time.Time `json:"completed_at,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the TaskQuery when eager-loading is set.
|
|
Edges TaskEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// TaskEdges holds the relations/edges for other nodes in the graph.
|
|
type TaskEdges struct {
|
|
// ProjectTasks holds the value of the project_tasks edge.
|
|
ProjectTasks []*ProjectTask `json:"project_tasks,omitempty"`
|
|
// User holds the value of the user edge.
|
|
User *User `json:"user,omitempty"`
|
|
// Vms holds the value of the vms edge.
|
|
Vms []*VirtualMachine `json:"vms,omitempty"`
|
|
// GitBotTasks holds the value of the git_bot_tasks edge.
|
|
GitBotTasks []*GitBotTask `json:"git_bot_tasks,omitempty"`
|
|
// TaskVms holds the value of the task_vms edge.
|
|
TaskVms []*TaskVirtualMachine `json:"task_vms,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [5]bool
|
|
}
|
|
|
|
// ProjectTasksOrErr returns the ProjectTasks value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) ProjectTasksOrErr() ([]*ProjectTask, error) {
|
|
if e.loadedTypes[0] {
|
|
return e.ProjectTasks, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "project_tasks"}
|
|
}
|
|
|
|
// 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 TaskEdges) 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"}
|
|
}
|
|
|
|
// VmsOrErr returns the Vms value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) VmsOrErr() ([]*VirtualMachine, error) {
|
|
if e.loadedTypes[2] {
|
|
return e.Vms, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "vms"}
|
|
}
|
|
|
|
// GitBotTasksOrErr returns the GitBotTasks value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) GitBotTasksOrErr() ([]*GitBotTask, error) {
|
|
if e.loadedTypes[3] {
|
|
return e.GitBotTasks, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "git_bot_tasks"}
|
|
}
|
|
|
|
// TaskVmsOrErr returns the TaskVms value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e TaskEdges) TaskVmsOrErr() ([]*TaskVirtualMachine, error) {
|
|
if e.loadedTypes[4] {
|
|
return e.TaskVms, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "task_vms"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Task) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case task.FieldKind, task.FieldSubType, task.FieldContent, task.FieldSummary, task.FieldStatus:
|
|
values[i] = new(sql.NullString)
|
|
case task.FieldDeletedAt, task.FieldCreatedAt, task.FieldUpdatedAt, task.FieldCompletedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case task.FieldID, task.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 Task fields.
|
|
func (_m *Task) 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 task.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 task.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 task.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 task.FieldKind:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field kind", values[i])
|
|
} else if value.Valid {
|
|
_m.Kind = consts.TaskType(value.String)
|
|
}
|
|
case task.FieldSubType:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field sub_type", values[i])
|
|
} else if value.Valid {
|
|
_m.SubType = consts.TaskSubType(value.String)
|
|
}
|
|
case task.FieldContent:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field content", values[i])
|
|
} else if value.Valid {
|
|
_m.Content = value.String
|
|
}
|
|
case task.FieldSummary:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field summary", values[i])
|
|
} else if value.Valid {
|
|
_m.Summary = value.String
|
|
}
|
|
case task.FieldStatus:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
|
} else if value.Valid {
|
|
_m.Status = consts.TaskStatus(value.String)
|
|
}
|
|
case task.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 task.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
|
|
}
|
|
case task.FieldCompletedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field completed_at", values[i])
|
|
} else if value.Valid {
|
|
_m.CompletedAt = 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 Task.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *Task) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryProjectTasks queries the "project_tasks" edge of the Task entity.
|
|
func (_m *Task) QueryProjectTasks() *ProjectTaskQuery {
|
|
return NewTaskClient(_m.config).QueryProjectTasks(_m)
|
|
}
|
|
|
|
// QueryUser queries the "user" edge of the Task entity.
|
|
func (_m *Task) QueryUser() *UserQuery {
|
|
return NewTaskClient(_m.config).QueryUser(_m)
|
|
}
|
|
|
|
// QueryVms queries the "vms" edge of the Task entity.
|
|
func (_m *Task) QueryVms() *VirtualMachineQuery {
|
|
return NewTaskClient(_m.config).QueryVms(_m)
|
|
}
|
|
|
|
// QueryGitBotTasks queries the "git_bot_tasks" edge of the Task entity.
|
|
func (_m *Task) QueryGitBotTasks() *GitBotTaskQuery {
|
|
return NewTaskClient(_m.config).QueryGitBotTasks(_m)
|
|
}
|
|
|
|
// QueryTaskVms queries the "task_vms" edge of the Task entity.
|
|
func (_m *Task) QueryTaskVms() *TaskVirtualMachineQuery {
|
|
return NewTaskClient(_m.config).QueryTaskVms(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this Task.
|
|
// Note that you need to call Task.Unwrap() before calling this method if this Task
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *Task) Update() *TaskUpdateOne {
|
|
return NewTaskClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the Task 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 *Task) Unwrap() *Task {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: Task is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *Task) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Task(")
|
|
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("kind=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Kind))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("sub_type=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.SubType))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("content=")
|
|
builder.WriteString(_m.Content)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("summary=")
|
|
builder.WriteString(_m.Summary)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("status=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
|
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.WriteString(", ")
|
|
builder.WriteString("completed_at=")
|
|
builder.WriteString(_m.CompletedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Tasks is a parsable slice of Task.
|
|
type Tasks []*Task
|