Files
MonkeyCode/backend/ent/schema/user.go
2025-06-30 19:04:09 +08:00

50 lines
1.0 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"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Table: "users",
},
}
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}),
field.String("username").Unique(),
field.String("password"),
field.String("email").Unique(),
field.String("status").GoType(consts.UserStatus("")).Default(string(consts.UserStatusActive)),
field.Time("created_at").Default(time.Now),
field.Time("updated_at").Default(time.Now),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("login_histories", UserLoginHistory.Type),
edge.To("models", Model.Type),
edge.To("tasks", Task.Type),
}
}