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 游标
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/chaitin/MonkeyCode/backend/consts"
|
|
"github.com/chaitin/MonkeyCode/backend/pkg/entx"
|
|
)
|
|
|
|
// Task holds the schema definition for the Task entity.
|
|
type Task struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Task) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Table("tasks"),
|
|
entx.NewCursor(entx.CursorKindCreatedAt),
|
|
}
|
|
}
|
|
|
|
func (Task) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
entx.SoftDeleteMixin2{},
|
|
}
|
|
}
|
|
|
|
// Fields of the Task.
|
|
func (Task) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.UUID("id", uuid.UUID{}),
|
|
field.UUID("user_id", uuid.UUID{}).Unique(),
|
|
field.String("kind").GoType(consts.TaskType("")),
|
|
field.String("sub_type").GoType(consts.TaskSubType("")).Optional(),
|
|
field.Text("content").NotEmpty(),
|
|
field.Text("summary").Optional(),
|
|
field.String("status").GoType(consts.TaskStatus("")),
|
|
field.Time("created_at").Default(time.Now),
|
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
|
field.Time("completed_at").Optional(),
|
|
}
|
|
}
|
|
|
|
// Edges of the Task.
|
|
func (Task) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.To("project_tasks", ProjectTask.Type),
|
|
edge.From("user", User.Type).Ref("tasks").Field("user_id").Unique().Required(),
|
|
edge.From("vms", VirtualMachine.Type).Through("task_vms", TaskVirtualMachine.Type).Ref("tasks"),
|
|
edge.To("git_bot_tasks", GitBotTask.Type),
|
|
}
|
|
}
|