forked from mirrors/homebox
generate database schemas
This commit is contained in:
parent
4c76f6b367
commit
63cfeffc4d
70 changed files with 26933 additions and 1398 deletions
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
@ -6,11 +6,13 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/content/backend/ent/authtokens"
|
||||
"github.com/hay-kot/content/backend/ent/group"
|
||||
"github.com/hay-kot/content/backend/ent/user"
|
||||
)
|
||||
|
||||
|
@ -21,6 +23,34 @@ type UserCreate struct {
|
|||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (uc *UserCreate) SetCreatedAt(t time.Time) *UserCreate {
|
||||
uc.mutation.SetCreatedAt(t)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (uc *UserCreate) SetNillableCreatedAt(t *time.Time) *UserCreate {
|
||||
if t != nil {
|
||||
uc.SetCreatedAt(*t)
|
||||
}
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (uc *UserCreate) SetUpdatedAt(t time.Time) *UserCreate {
|
||||
uc.mutation.SetUpdatedAt(t)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (uc *UserCreate) SetNillableUpdatedAt(t *time.Time) *UserCreate {
|
||||
if t != nil {
|
||||
uc.SetUpdatedAt(*t)
|
||||
}
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (uc *UserCreate) SetName(s string) *UserCreate {
|
||||
uc.mutation.SetName(s)
|
||||
|
@ -67,15 +97,26 @@ func (uc *UserCreate) SetNillableID(u *uuid.UUID) *UserCreate {
|
|||
return uc
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group" edge to the Group entity by ID.
|
||||
func (uc *UserCreate) SetGroupID(id uuid.UUID) *UserCreate {
|
||||
uc.mutation.SetGroupID(id)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (uc *UserCreate) SetGroup(g *Group) *UserCreate {
|
||||
return uc.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// AddAuthTokenIDs adds the "auth_tokens" edge to the AuthTokens entity by IDs.
|
||||
func (uc *UserCreate) AddAuthTokenIDs(ids ...int) *UserCreate {
|
||||
func (uc *UserCreate) AddAuthTokenIDs(ids ...uuid.UUID) *UserCreate {
|
||||
uc.mutation.AddAuthTokenIDs(ids...)
|
||||
return uc
|
||||
}
|
||||
|
||||
// AddAuthTokens adds the "auth_tokens" edges to the AuthTokens entity.
|
||||
func (uc *UserCreate) AddAuthTokens(a ...*AuthTokens) *UserCreate {
|
||||
ids := make([]int, len(a))
|
||||
ids := make([]uuid.UUID, len(a))
|
||||
for i := range a {
|
||||
ids[i] = a[i].ID
|
||||
}
|
||||
|
@ -122,9 +163,15 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
|
|||
}
|
||||
mut = uc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uc.mutation); err != nil {
|
||||
v, err := mut.Mutate(ctx, uc.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*User)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
@ -153,6 +200,14 @@ func (uc *UserCreate) ExecX(ctx context.Context) {
|
|||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (uc *UserCreate) defaults() {
|
||||
if _, ok := uc.mutation.CreatedAt(); !ok {
|
||||
v := user.DefaultCreatedAt()
|
||||
uc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := uc.mutation.UpdatedAt(); !ok {
|
||||
v := user.DefaultUpdatedAt()
|
||||
uc.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := uc.mutation.IsSuperuser(); !ok {
|
||||
v := user.DefaultIsSuperuser
|
||||
uc.mutation.SetIsSuperuser(v)
|
||||
|
@ -165,6 +220,12 @@ func (uc *UserCreate) defaults() {
|
|||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uc *UserCreate) check() error {
|
||||
if _, ok := uc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)}
|
||||
}
|
||||
if _, ok := uc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)}
|
||||
}
|
||||
if _, ok := uc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "User.name"`)}
|
||||
}
|
||||
|
@ -192,6 +253,9 @@ func (uc *UserCreate) check() error {
|
|||
if _, ok := uc.mutation.IsSuperuser(); !ok {
|
||||
return &ValidationError{Name: "is_superuser", err: errors.New(`ent: missing required field "User.is_superuser"`)}
|
||||
}
|
||||
if _, ok := uc.mutation.GroupID(); !ok {
|
||||
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "User.group"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -199,7 +263,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
|||
_node, _spec := uc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
@ -228,6 +292,22 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := uc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: user.FieldCreatedAt,
|
||||
})
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := uc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: user.FieldUpdatedAt,
|
||||
})
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := uc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
|
@ -260,6 +340,26 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
})
|
||||
_node.IsSuperuser = value
|
||||
}
|
||||
if nodes := uc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: user.GroupTable,
|
||||
Columns: []string{user.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: group.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.group_users = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := uc.mutation.AuthTokensIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
@ -269,7 +369,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Type: field.TypeUUID,
|
||||
Column: authtokens.FieldID,
|
||||
},
|
||||
},
|
||||
|
@ -315,7 +415,7 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
|||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ucb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue