2022-08-30 02:30:36 +00:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"entgo.io/ent"
|
2022-09-04 02:42:03 +00:00
|
|
|
"entgo.io/ent/dialect/entsql"
|
2022-08-30 02:30:36 +00:00
|
|
|
"entgo.io/ent/schema/edge"
|
|
|
|
"entgo.io/ent/schema/field"
|
2022-09-24 19:33:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/ent/schema/mixins"
|
2022-08-30 02:30:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// User holds the schema definition for the User entity.
|
|
|
|
type User struct {
|
|
|
|
ent.Schema
|
|
|
|
}
|
|
|
|
|
2022-08-30 18:04:50 +00:00
|
|
|
func (User) Mixin() []ent.Mixin {
|
|
|
|
return []ent.Mixin{
|
|
|
|
mixins.BaseMixin{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:30:36 +00:00
|
|
|
// Fields of the User.
|
|
|
|
func (User) Fields() []ent.Field {
|
|
|
|
return []ent.Field{
|
|
|
|
field.String("name").
|
2022-08-30 18:04:50 +00:00
|
|
|
MaxLen(255).
|
2022-08-30 02:30:36 +00:00
|
|
|
NotEmpty(),
|
|
|
|
field.String("email").
|
2022-08-30 18:04:50 +00:00
|
|
|
MaxLen(255).
|
2022-08-30 02:30:36 +00:00
|
|
|
NotEmpty().
|
|
|
|
Unique(),
|
|
|
|
field.String("password").
|
2022-08-30 18:04:50 +00:00
|
|
|
MaxLen(255).
|
2022-08-30 02:30:36 +00:00
|
|
|
NotEmpty().
|
|
|
|
Sensitive(),
|
|
|
|
field.Bool("is_superuser").
|
|
|
|
Default(false),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edges of the User.
|
|
|
|
func (User) Edges() []ent.Edge {
|
|
|
|
return []ent.Edge{
|
2022-08-30 18:04:50 +00:00
|
|
|
edge.From("group", Group.Type).
|
|
|
|
Ref("users").
|
|
|
|
Required().
|
|
|
|
Unique(),
|
2022-09-04 02:42:03 +00:00
|
|
|
edge.To("auth_tokens", AuthTokens.Type).Annotations(entsql.Annotation{
|
|
|
|
OnDelete: entsql.Cascade,
|
|
|
|
}),
|
2022-08-30 02:30:36 +00:00
|
|
|
}
|
|
|
|
}
|