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

55 lines
1.4 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/pkg/entx"
)
// TeamGroup holds the schema definition for the TeamGroup entity.
type TeamGroup struct {
ent.Schema
}
func (TeamGroup) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Table("team_groups"),
entx.NewCursor(entx.CursorKindCreatedAt),
}
}
func (TeamGroup) Mixin() []ent.Mixin {
return []ent.Mixin{
entx.SoftDeleteMixin2{},
}
}
// Fields of the TeamGroup.
func (TeamGroup) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Unique(),
field.UUID("team_id", uuid.UUID{}),
field.String("name"),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
// Edges of the TeamGroup.
func (TeamGroup) Edges() []ent.Edge {
return []ent.Edge{
edge.From("members", User.Type).Ref("groups").Through("team_group_members", TeamGroupMember.Type),
edge.From("team", Team.Type).Ref("groups").Field("team_id").Unique().Required(),
edge.To("models", Model.Type).Through("team_group_models", TeamGroupModel.Type),
edge.To("images", Image.Type).Through("team_group_images", TeamGroupImage.Type),
edge.To("hosts", Host.Type).Through("team_group_hosts", TeamGroupHost.Type),
}
}