mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-15 23:29:53 +00:00
generate database schemas
This commit is contained in:
parent
4c76f6b367
commit
63cfeffc4d
70 changed files with 26933 additions and 1398 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// AuthTokens holds the schema definition for the AuthTokens entity.
|
||||
|
@ -14,6 +15,12 @@ type AuthTokens struct {
|
|||
ent.Schema
|
||||
}
|
||||
|
||||
func (AuthTokens) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the AuthTokens.
|
||||
func (AuthTokens) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
|
@ -21,8 +28,6 @@ func (AuthTokens) Fields() []ent.Field {
|
|||
Unique(),
|
||||
field.Time("expires_at").
|
||||
Default(func() time.Time { return time.Now().Add(time.Hour * 24 * 7) }),
|
||||
field.Time("created_at").
|
||||
Default(time.Now),
|
||||
}
|
||||
}
|
||||
|
41
backend/ent/schema/group.go
Normal file
41
backend/ent/schema/group.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// Group holds the schema definition for the Group entity.
|
||||
type Group struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Group) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Home.
|
||||
func (Group) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
field.Enum("currency").
|
||||
Default("usd").
|
||||
Values("usd"), // TODO: add more currencies
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Home.
|
||||
func (Group) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("users", User.Type),
|
||||
edge.To("locations", Location.Type),
|
||||
edge.To("items", Item.Type),
|
||||
edge.To("labels", Label.Type),
|
||||
}
|
||||
}
|
80
backend/ent/schema/item.go
Normal file
80
backend/ent/schema/item.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// Item holds the schema definition for the Item entity.
|
||||
type Item struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Item) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
mixins.DetailsMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Item.
|
||||
func (Item) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("notes").
|
||||
MaxLen(1000).
|
||||
Optional(),
|
||||
// ------------------------------------
|
||||
// item identification
|
||||
field.String("serial_number").
|
||||
MaxLen(255).
|
||||
Optional(),
|
||||
field.String("model_number").
|
||||
MaxLen(255).
|
||||
Optional(),
|
||||
field.String("manufacturer").
|
||||
MaxLen(255).
|
||||
Optional(),
|
||||
// ------------------------------------
|
||||
// item purchase
|
||||
field.Time("purchase_time").
|
||||
Optional(),
|
||||
field.String("purchase_from").
|
||||
Optional(),
|
||||
field.Float("purchase_price").
|
||||
Default(0),
|
||||
field.UUID("purchase_receipt_id", uuid.UUID{}).
|
||||
Optional(),
|
||||
// ------------------------------------
|
||||
// Sold Details
|
||||
field.Time("sold_time").
|
||||
Optional(),
|
||||
field.String("sold_to").
|
||||
Optional(),
|
||||
field.Float("sold_price").
|
||||
Default(0),
|
||||
field.UUID("sold_receipt_id", uuid.UUID{}).
|
||||
Optional(),
|
||||
field.String("sold_notes").
|
||||
MaxLen(1000).
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Item.
|
||||
func (Item) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref("items").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.From("location", Location.Type).
|
||||
Ref("items").
|
||||
Unique(),
|
||||
edge.To("fields", ItemField.Type),
|
||||
edge.From("label", Label.Type).
|
||||
Ref("items"),
|
||||
}
|
||||
}
|
48
backend/ent/schema/item_field.go
Normal file
48
backend/ent/schema/item_field.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// ItemField holds the schema definition for the ItemField entity.
|
||||
type ItemField struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (ItemField) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
mixins.DetailsMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the ItemField.
|
||||
func (ItemField) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("type").
|
||||
Values("text", "number", "boolean", "time"),
|
||||
field.String("text_value").
|
||||
MaxLen(500).
|
||||
Optional(),
|
||||
field.Int("number_value").
|
||||
Optional(),
|
||||
field.Bool("boolean_value").
|
||||
Default(false),
|
||||
field.Time("time_value").
|
||||
Default(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the ItemField.
|
||||
func (ItemField) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("item", Item.Type).
|
||||
Ref("fields").
|
||||
Unique(),
|
||||
}
|
||||
}
|
40
backend/ent/schema/label.go
Normal file
40
backend/ent/schema/label.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// Label holds the schema definition for the Label entity.
|
||||
type Label struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Label) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
mixins.DetailsMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Label.
|
||||
func (Label) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("color").
|
||||
MaxLen(255).
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Label.
|
||||
func (Label) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref("labels").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.To("items", Item.Type),
|
||||
}
|
||||
}
|
35
backend/ent/schema/location.go
Normal file
35
backend/ent/schema/location.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// Location holds the schema definition for the Location entity.
|
||||
type Location struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Location) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
mixins.DetailsMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Location.
|
||||
func (Location) Fields() []ent.Field {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edges of the Location.
|
||||
func (Location) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref("locations").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.To("items", Item.Type),
|
||||
}
|
||||
}
|
42
backend/ent/schema/mixins/base.go
Normal file
42
backend/ent/schema/mixins/base.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package mixins
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type BaseMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (BaseMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New),
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Default(time.Now),
|
||||
field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
UpdateDefault(time.Now),
|
||||
}
|
||||
}
|
||||
|
||||
type DetailsMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (DetailsMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
field.String("description").
|
||||
MaxLen(1000).
|
||||
Optional(),
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import (
|
|||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/content/backend/ent/schema/mixins"
|
||||
)
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
|
@ -12,17 +12,24 @@ type User struct {
|
|||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New),
|
||||
field.String("name").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
field.String("email").
|
||||
MaxLen(255).
|
||||
NotEmpty().
|
||||
Unique(),
|
||||
field.String("password").
|
||||
MaxLen(255).
|
||||
NotEmpty().
|
||||
Sensitive(),
|
||||
field.Bool("is_superuser").
|
||||
|
@ -33,6 +40,10 @@ func (User) Fields() []ent.Field {
|
|||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref("users").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.To("auth_tokens", AuthTokens.Type),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue