mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-06 02:28:35 +00:00
Initial commit
This commit is contained in:
commit
29f583e936
135 changed files with 18463 additions and 0 deletions
43
backend/ent/schema/authtokens.go
Normal file
43
backend/ent/schema/authtokens.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// AuthTokens holds the schema definition for the AuthTokens entity.
|
||||
type AuthTokens struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the AuthTokens.
|
||||
func (AuthTokens) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Bytes("token").
|
||||
Unique(),
|
||||
field.Time("expires_at").
|
||||
Default(func() time.Time { return time.Now().Add(time.Hour * 24 * 7) }),
|
||||
field.Time("created_at").
|
||||
Default(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the AuthTokens.
|
||||
func (AuthTokens) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Ref("auth_tokens").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (AuthTokens) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
// non-unique index.
|
||||
index.Fields("token"),
|
||||
}
|
||||
}
|
38
backend/ent/schema/user.go
Normal file
38
backend/ent/schema/user.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// 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.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New),
|
||||
field.String("name").
|
||||
NotEmpty(),
|
||||
field.String("email").
|
||||
NotEmpty().
|
||||
Unique(),
|
||||
field.String("password").
|
||||
NotEmpty().
|
||||
Sensitive(),
|
||||
field.Bool("is_superuser").
|
||||
Default(false),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("auth_tokens", AuthTokens.Type),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue