55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package schema
|
|
|
|
import (
|
|
"juwan-backend/pkg/types"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/lib/pq"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
var playerDefaultRating = decimal.RequireFromString("5.00")
|
|
|
|
// Players holds the schema definition for the Players entity.
|
|
type Players struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the Players.
|
|
func (Players) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("id").Immutable().Unique(),
|
|
field.Int64("user_id").Unique(),
|
|
field.String("status").MaxLen(20).Default("offline"),
|
|
field.Bool("gender").Default(true),
|
|
field.Other("rating", decimal.Decimal{}).
|
|
Optional().
|
|
Default(playerDefaultRating).
|
|
SchemaType(map[string]string{
|
|
dialect.Postgres: "decimal(3,2)",
|
|
}),
|
|
field.Int("total_orders").Optional().Default(0),
|
|
field.Int("completed_orders").Optional().Default(0),
|
|
field.Int64("shop_id").Optional().Nillable(),
|
|
field.Other("tags", types.TextArray{}).SchemaType(map[string]string{
|
|
dialect.Postgres: "text[]",
|
|
}).Optional(),
|
|
field.Other("games", pq.Int64Array{}).
|
|
Optional().
|
|
Default(pq.Int64Array{}).
|
|
SchemaType(map[string]string{
|
|
dialect.Postgres: "bigint[]",
|
|
}),
|
|
field.Time("created_at").Default(time.Now).Immutable(),
|
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
|
}
|
|
}
|
|
|
|
// Edges of the Players.
|
|
func (Players) Edges() []ent.Edge {
|
|
return nil
|
|
}
|