Files
MonkeyCode/backend/db/gitbot.go
yokowu 34320f9ed5 feat(phase6): 添加 gitbot/gittask 实体 schema 和 migration
- 新增 git_bots, git_bot_users, git_bot_tasks, project_git_bots 表
- 添加 user, host, project 到 gitbot 的关联边
- 使用 soft delete 和 created_at 游标
2026-03-19 18:14:53 +08:00

295 lines
9.9 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/gitbot"
"github.com/chaitin/MonkeyCode/backend/db/host"
"github.com/google/uuid"
)
// GitBot is the model entity for the GitBot schema.
type GitBot 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"`
// HostID holds the value of the "host_id" field.
HostID string `json:"host_id,omitempty"`
// Token holds the value of the "token" field.
Token string `json:"token,omitempty"`
// SecretToken holds the value of the "secret_token" field.
SecretToken string `json:"secret_token,omitempty"`
// Platform holds the value of the "platform" field.
Platform consts.GitPlatform `json:"platform,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 GitBotQuery when eager-loading is set.
Edges GitBotEdges `json:"edges"`
selectValues sql.SelectValues
}
// GitBotEdges holds the relations/edges for other nodes in the graph.
type GitBotEdges struct {
// GitBotTasks holds the value of the git_bot_tasks edge.
GitBotTasks []*GitBotTask `json:"git_bot_tasks,omitempty"`
// Host holds the value of the host edge.
Host *Host `json:"host,omitempty"`
// Users holds the value of the users edge.
Users []*User `json:"users,omitempty"`
// Projects holds the value of the projects edge.
Projects []*Project `json:"projects,omitempty"`
// GitBotUsers holds the value of the git_bot_users edge.
GitBotUsers []*GitBotUser `json:"git_bot_users,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 [6]bool
}
// GitBotTasksOrErr returns the GitBotTasks value or an error if the edge
// was not loaded in eager-loading.
func (e GitBotEdges) GitBotTasksOrErr() ([]*GitBotTask, error) {
if e.loadedTypes[0] {
return e.GitBotTasks, nil
}
return nil, &NotLoadedError{edge: "git_bot_tasks"}
}
// 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 GitBotEdges) 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"}
}
// UsersOrErr returns the Users value or an error if the edge
// was not loaded in eager-loading.
func (e GitBotEdges) UsersOrErr() ([]*User, error) {
if e.loadedTypes[2] {
return e.Users, nil
}
return nil, &NotLoadedError{edge: "users"}
}
// ProjectsOrErr returns the Projects value or an error if the edge
// was not loaded in eager-loading.
func (e GitBotEdges) ProjectsOrErr() ([]*Project, error) {
if e.loadedTypes[3] {
return e.Projects, nil
}
return nil, &NotLoadedError{edge: "projects"}
}
// GitBotUsersOrErr returns the GitBotUsers value or an error if the edge
// was not loaded in eager-loading.
func (e GitBotEdges) GitBotUsersOrErr() ([]*GitBotUser, error) {
if e.loadedTypes[4] {
return e.GitBotUsers, nil
}
return nil, &NotLoadedError{edge: "git_bot_users"}
}
// ProjectGitBotsOrErr returns the ProjectGitBots value or an error if the edge
// was not loaded in eager-loading.
func (e GitBotEdges) ProjectGitBotsOrErr() ([]*ProjectGitBot, error) {
if e.loadedTypes[5] {
return e.ProjectGitBots, nil
}
return nil, &NotLoadedError{edge: "project_git_bots"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*GitBot) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case gitbot.FieldName, gitbot.FieldHostID, gitbot.FieldToken, gitbot.FieldSecretToken, gitbot.FieldPlatform:
values[i] = new(sql.NullString)
case gitbot.FieldDeletedAt, gitbot.FieldCreatedAt:
values[i] = new(sql.NullTime)
case gitbot.FieldID, gitbot.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 GitBot fields.
func (_m *GitBot) 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 gitbot.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 gitbot.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 gitbot.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 gitbot.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 gitbot.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 gitbot.FieldToken:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field token", values[i])
} else if value.Valid {
_m.Token = value.String
}
case gitbot.FieldSecretToken:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field secret_token", values[i])
} else if value.Valid {
_m.SecretToken = value.String
}
case gitbot.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 gitbot.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 GitBot.
// This includes values selected through modifiers, order, etc.
func (_m *GitBot) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryGitBotTasks queries the "git_bot_tasks" edge of the GitBot entity.
func (_m *GitBot) QueryGitBotTasks() *GitBotTaskQuery {
return NewGitBotClient(_m.config).QueryGitBotTasks(_m)
}
// QueryHost queries the "host" edge of the GitBot entity.
func (_m *GitBot) QueryHost() *HostQuery {
return NewGitBotClient(_m.config).QueryHost(_m)
}
// QueryUsers queries the "users" edge of the GitBot entity.
func (_m *GitBot) QueryUsers() *UserQuery {
return NewGitBotClient(_m.config).QueryUsers(_m)
}
// QueryProjects queries the "projects" edge of the GitBot entity.
func (_m *GitBot) QueryProjects() *ProjectQuery {
return NewGitBotClient(_m.config).QueryProjects(_m)
}
// QueryGitBotUsers queries the "git_bot_users" edge of the GitBot entity.
func (_m *GitBot) QueryGitBotUsers() *GitBotUserQuery {
return NewGitBotClient(_m.config).QueryGitBotUsers(_m)
}
// QueryProjectGitBots queries the "project_git_bots" edge of the GitBot entity.
func (_m *GitBot) QueryProjectGitBots() *ProjectGitBotQuery {
return NewGitBotClient(_m.config).QueryProjectGitBots(_m)
}
// Update returns a builder for updating this GitBot.
// Note that you need to call GitBot.Unwrap() before calling this method if this GitBot
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *GitBot) Update() *GitBotUpdateOne {
return NewGitBotClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the GitBot 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 *GitBot) Unwrap() *GitBot {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("db: GitBot is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *GitBot) String() string {
var builder strings.Builder
builder.WriteString("GitBot(")
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("host_id=")
builder.WriteString(_m.HostID)
builder.WriteString(", ")
builder.WriteString("token=")
builder.WriteString(_m.Token)
builder.WriteString(", ")
builder.WriteString("secret_token=")
builder.WriteString(_m.SecretToken)
builder.WriteString(", ")
builder.WriteString("platform=")
builder.WriteString(fmt.Sprintf("%v", _m.Platform))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// GitBots is a parsable slice of GitBot.
type GitBots []*GitBot