mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-23 04:09:15 +08:00
- 新增 git_bots, git_bot_users, git_bot_tasks, project_git_bots 表 - 添加 user, host, project 到 gitbot 的关联边 - 使用 soft delete 和 created_at 游标
382 lines
14 KiB
Go
382 lines
14 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/chaitin/MonkeyCode/backend/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/db/gitidentity"
|
|
"github.com/chaitin/MonkeyCode/backend/db/image"
|
|
"github.com/chaitin/MonkeyCode/backend/db/project"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Project is the model entity for the Project schema.
|
|
type Project 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"`
|
|
// Name holds the value of the "name" field.
|
|
Name string `json:"name,omitempty"`
|
|
// Description holds the value of the "description" field.
|
|
Description string `json:"description,omitempty"`
|
|
// Platform holds the value of the "platform" field.
|
|
Platform consts.GitPlatform `json:"platform,omitempty"`
|
|
// RepoURL holds the value of the "repo_url" field.
|
|
RepoURL string `json:"repo_url,omitempty"`
|
|
// Branch holds the value of the "branch" field.
|
|
Branch string `json:"branch,omitempty"`
|
|
// GitIdentityID holds the value of the "git_identity_id" field.
|
|
GitIdentityID uuid.UUID `json:"git_identity_id,omitempty"`
|
|
// ImageID holds the value of the "image_id" field.
|
|
ImageID uuid.UUID `json:"image_id,omitempty"`
|
|
// EnvVariables holds the value of the "env_variables" field.
|
|
EnvVariables map[string]interface{} `json:"env_variables,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 ProjectQuery when eager-loading is set.
|
|
Edges ProjectEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// ProjectEdges holds the relations/edges for other nodes in the graph.
|
|
type ProjectEdges struct {
|
|
// User holds the value of the user edge.
|
|
User *User `json:"user,omitempty"`
|
|
// GitIdentity holds the value of the git_identity edge.
|
|
GitIdentity *GitIdentity `json:"git_identity,omitempty"`
|
|
// Image holds the value of the image edge.
|
|
Image *Image `json:"image,omitempty"`
|
|
// Issues holds the value of the issues edge.
|
|
Issues []*ProjectIssue `json:"issues,omitempty"`
|
|
// Collaborators holds the value of the collaborators edge.
|
|
Collaborators []*ProjectCollaborator `json:"collaborators,omitempty"`
|
|
// ProjectTasks holds the value of the project_tasks edge.
|
|
ProjectTasks []*ProjectTask `json:"project_tasks,omitempty"`
|
|
// GitBots holds the value of the git_bots edge.
|
|
GitBots []*GitBot `json:"git_bots,omitempty"`
|
|
// ProjectGitBots holds the value of the project_git_bots edge.
|
|
ProjectGitBots []*ProjectGitBot `json:"project_git_bots,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [8]bool
|
|
}
|
|
|
|
// 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 ProjectEdges) UserOrErr() (*User, error) {
|
|
if e.User != nil {
|
|
return e.User, nil
|
|
} else if e.loadedTypes[0] {
|
|
return nil, &NotFoundError{label: user.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "user"}
|
|
}
|
|
|
|
// GitIdentityOrErr returns the GitIdentity value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e ProjectEdges) GitIdentityOrErr() (*GitIdentity, error) {
|
|
if e.GitIdentity != nil {
|
|
return e.GitIdentity, nil
|
|
} else if e.loadedTypes[1] {
|
|
return nil, &NotFoundError{label: gitidentity.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "git_identity"}
|
|
}
|
|
|
|
// ImageOrErr returns the Image value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e ProjectEdges) ImageOrErr() (*Image, error) {
|
|
if e.Image != nil {
|
|
return e.Image, nil
|
|
} else if e.loadedTypes[2] {
|
|
return nil, &NotFoundError{label: image.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "image"}
|
|
}
|
|
|
|
// IssuesOrErr returns the Issues value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ProjectEdges) IssuesOrErr() ([]*ProjectIssue, error) {
|
|
if e.loadedTypes[3] {
|
|
return e.Issues, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "issues"}
|
|
}
|
|
|
|
// CollaboratorsOrErr returns the Collaborators value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ProjectEdges) CollaboratorsOrErr() ([]*ProjectCollaborator, error) {
|
|
if e.loadedTypes[4] {
|
|
return e.Collaborators, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "collaborators"}
|
|
}
|
|
|
|
// ProjectTasksOrErr returns the ProjectTasks value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ProjectEdges) ProjectTasksOrErr() ([]*ProjectTask, error) {
|
|
if e.loadedTypes[5] {
|
|
return e.ProjectTasks, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "project_tasks"}
|
|
}
|
|
|
|
// GitBotsOrErr returns the GitBots value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ProjectEdges) GitBotsOrErr() ([]*GitBot, error) {
|
|
if e.loadedTypes[6] {
|
|
return e.GitBots, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "git_bots"}
|
|
}
|
|
|
|
// ProjectGitBotsOrErr returns the ProjectGitBots value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ProjectEdges) ProjectGitBotsOrErr() ([]*ProjectGitBot, error) {
|
|
if e.loadedTypes[7] {
|
|
return e.ProjectGitBots, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "project_git_bots"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Project) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case project.FieldEnvVariables:
|
|
values[i] = new([]byte)
|
|
case project.FieldName, project.FieldDescription, project.FieldPlatform, project.FieldRepoURL, project.FieldBranch:
|
|
values[i] = new(sql.NullString)
|
|
case project.FieldDeletedAt, project.FieldCreatedAt, project.FieldUpdatedAt:
|
|
values[i] = new(sql.NullTime)
|
|
case project.FieldID, project.FieldUserID, project.FieldGitIdentityID, project.FieldImageID:
|
|
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 Project fields.
|
|
func (_m *Project) 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 project.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 project.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 project.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 project.FieldName:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
|
} else if value.Valid {
|
|
_m.Name = value.String
|
|
}
|
|
case project.FieldDescription:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
|
} else if value.Valid {
|
|
_m.Description = value.String
|
|
}
|
|
case project.FieldPlatform:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field platform", values[i])
|
|
} else if value.Valid {
|
|
_m.Platform = consts.GitPlatform(value.String)
|
|
}
|
|
case project.FieldRepoURL:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field repo_url", values[i])
|
|
} else if value.Valid {
|
|
_m.RepoURL = value.String
|
|
}
|
|
case project.FieldBranch:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field branch", values[i])
|
|
} else if value.Valid {
|
|
_m.Branch = value.String
|
|
}
|
|
case project.FieldGitIdentityID:
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
return fmt.Errorf("unexpected type %T for field git_identity_id", values[i])
|
|
} else if value != nil {
|
|
_m.GitIdentityID = *value
|
|
}
|
|
case project.FieldImageID:
|
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
return fmt.Errorf("unexpected type %T for field image_id", values[i])
|
|
} else if value != nil {
|
|
_m.ImageID = *value
|
|
}
|
|
case project.FieldEnvVariables:
|
|
if value, ok := values[i].(*[]byte); !ok {
|
|
return fmt.Errorf("unexpected type %T for field env_variables", values[i])
|
|
} else if value != nil && len(*value) > 0 {
|
|
if err := json.Unmarshal(*value, &_m.EnvVariables); err != nil {
|
|
return fmt.Errorf("unmarshal field env_variables: %w", err)
|
|
}
|
|
}
|
|
case project.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 project.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 Project.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *Project) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryUser queries the "user" edge of the Project entity.
|
|
func (_m *Project) QueryUser() *UserQuery {
|
|
return NewProjectClient(_m.config).QueryUser(_m)
|
|
}
|
|
|
|
// QueryGitIdentity queries the "git_identity" edge of the Project entity.
|
|
func (_m *Project) QueryGitIdentity() *GitIdentityQuery {
|
|
return NewProjectClient(_m.config).QueryGitIdentity(_m)
|
|
}
|
|
|
|
// QueryImage queries the "image" edge of the Project entity.
|
|
func (_m *Project) QueryImage() *ImageQuery {
|
|
return NewProjectClient(_m.config).QueryImage(_m)
|
|
}
|
|
|
|
// QueryIssues queries the "issues" edge of the Project entity.
|
|
func (_m *Project) QueryIssues() *ProjectIssueQuery {
|
|
return NewProjectClient(_m.config).QueryIssues(_m)
|
|
}
|
|
|
|
// QueryCollaborators queries the "collaborators" edge of the Project entity.
|
|
func (_m *Project) QueryCollaborators() *ProjectCollaboratorQuery {
|
|
return NewProjectClient(_m.config).QueryCollaborators(_m)
|
|
}
|
|
|
|
// QueryProjectTasks queries the "project_tasks" edge of the Project entity.
|
|
func (_m *Project) QueryProjectTasks() *ProjectTaskQuery {
|
|
return NewProjectClient(_m.config).QueryProjectTasks(_m)
|
|
}
|
|
|
|
// QueryGitBots queries the "git_bots" edge of the Project entity.
|
|
func (_m *Project) QueryGitBots() *GitBotQuery {
|
|
return NewProjectClient(_m.config).QueryGitBots(_m)
|
|
}
|
|
|
|
// QueryProjectGitBots queries the "project_git_bots" edge of the Project entity.
|
|
func (_m *Project) QueryProjectGitBots() *ProjectGitBotQuery {
|
|
return NewProjectClient(_m.config).QueryProjectGitBots(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this Project.
|
|
// Note that you need to call Project.Unwrap() before calling this method if this Project
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *Project) Update() *ProjectUpdateOne {
|
|
return NewProjectClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the Project 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 *Project) Unwrap() *Project {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("db: Project is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *Project) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Project(")
|
|
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("name=")
|
|
builder.WriteString(_m.Name)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("description=")
|
|
builder.WriteString(_m.Description)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("platform=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Platform))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("repo_url=")
|
|
builder.WriteString(_m.RepoURL)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("branch=")
|
|
builder.WriteString(_m.Branch)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("git_identity_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.GitIdentityID))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("image_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.ImageID))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("env_variables=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.EnvVariables))
|
|
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()
|
|
}
|
|
|
|
// Projects is a parsable slice of Project.
|
|
type Projects []*Project
|