47 lines
912 B
Go
47 lines
912 B
Go
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"time"
|
|
)
|
|
|
|
// User holds the schema definition for the User entity.
|
|
type User struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the User.
|
|
func (User) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("username").
|
|
Unique().
|
|
NotEmpty(),
|
|
field.String("display_name").
|
|
Optional().
|
|
MaxLen(64),
|
|
field.String("email").
|
|
NotEmpty(),
|
|
field.String("password_hash").
|
|
Sensitive().
|
|
NotEmpty(),
|
|
field.Enum("status").
|
|
Values("active", "inactive", "banned").
|
|
Default("active"),
|
|
field.Time("created_at").
|
|
Default(time.Now),
|
|
field.Time("updated_at").
|
|
Default(time.Now).
|
|
UpdateDefault(time.Now),
|
|
}
|
|
}
|
|
|
|
// Edges of the User.
|
|
func (User) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.To("roles", Role.Type),
|
|
edge.To("contributors", Contributor.Type),
|
|
edge.To("media", Media.Type),
|
|
}
|
|
}
|