55 lines
1017 B
Go
55 lines
1017 B
Go
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"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).
|
|
Unique().
|
|
Immutable(),
|
|
field.String("username").
|
|
NotEmpty().
|
|
Unique(),
|
|
field.String("email").
|
|
NotEmpty().
|
|
Unique(),
|
|
field.Bytes("password").
|
|
Sensitive().
|
|
NotEmpty(),
|
|
field.Bool("is_admin").
|
|
Default(false),
|
|
field.Bool("is_active").
|
|
Default(true),
|
|
field.Time("created_at").
|
|
Default(time.Now).
|
|
Immutable(),
|
|
field.Time("updated_at").
|
|
Default(time.Now).
|
|
UpdateDefault(time.Now),
|
|
field.Time("last_login").
|
|
Default(time.Unix(0, 0)).
|
|
UpdateDefault(time.Now),
|
|
}
|
|
}
|
|
|
|
// Edges of the User.
|
|
func (User) Edges() []ent.Edge {
|
|
return nil
|
|
}
|