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

42 lines
878 B
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"
)
// TeamHost holds the schema definition for the TeamHost entity.
type TeamHost struct {
ent.Schema
}
func (TeamHost) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Table("team_hosts"),
}
}
// Fields of the TeamHost.
func (TeamHost) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Unique(),
field.UUID("team_id", uuid.UUID{}),
field.String("host_id"),
field.Time("created_at").Default(time.Now),
}
}
// Edges of the TeamHost.
func (TeamHost) Edges() []ent.Edge {
return []ent.Edge{
edge.To("team", Team.Type).Field("team_id").Unique().Required(),
edge.To("host", Host.Type).Field("host_id").Unique().Required(),
}
}