mirror of https://github.com/cloudreve/Cloudreve
feat: upgrade from community to pro / remove unused edges in storage policy
parent
9226d0c8ec
commit
cc69178310
|
@ -305,7 +305,12 @@ func (d *dependency) DBClient() *ent.Client {
|
||||||
d.rawEntClient = client
|
d.rawEntClient = client
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := inventory.InitializeDBClient(d.Logger(), d.rawEntClient, d.KV(), d.requiredDbVersion)
|
proSuffix := ""
|
||||||
|
if d.isPro {
|
||||||
|
proSuffix = "-pro"
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := inventory.InitializeDBClient(d.Logger(), d.rawEntClient, d.KV(), d.requiredDbVersion+proSuffix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.panicError(err)
|
d.panicError(err)
|
||||||
}
|
}
|
||||||
|
|
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 904efa8f6bacee4fccb1cdee620b6315c81d5f95
|
Subproject commit 587e9f29cf45c650546191a9a0ce7bac6642af2a
|
|
@ -1,7 +1,7 @@
|
||||||
services:
|
services:
|
||||||
pro:
|
pro:
|
||||||
image: cloudreve/cloudreve:latest
|
image: cloudreve/cloudreve:latest
|
||||||
container_name: cloudreve-pro-backend
|
container_name: cloudreve-backend
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgresql
|
- postgresql
|
||||||
- redis
|
- redis
|
||||||
|
|
|
@ -2083,22 +2083,6 @@ func (c *StoragePolicyClient) GetX(ctx context.Context, id int) *StoragePolicy {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryUsers queries the users edge of a StoragePolicy.
|
|
||||||
func (c *StoragePolicyClient) QueryUsers(sp *StoragePolicy) *UserQuery {
|
|
||||||
query := (&UserClient{config: c.config}).Query()
|
|
||||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
||||||
id := sp.ID
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(storagepolicy.Table, storagepolicy.FieldID, id),
|
|
||||||
sqlgraph.To(user.Table, user.FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, storagepolicy.UsersTable, storagepolicy.UsersColumn),
|
|
||||||
)
|
|
||||||
fromV = sqlgraph.Neighbors(sp.driver.Dialect(), step)
|
|
||||||
return fromV, nil
|
|
||||||
}
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGroups queries the groups edge of a StoragePolicy.
|
// QueryGroups queries the groups edge of a StoragePolicy.
|
||||||
func (c *StoragePolicyClient) QueryGroups(sp *StoragePolicy) *GroupQuery {
|
func (c *StoragePolicyClient) QueryGroups(sp *StoragePolicy) *GroupQuery {
|
||||||
query := (&GroupClient{config: c.config}).Query()
|
query := (&GroupClient{config: c.config}).Query()
|
||||||
|
|
|
@ -455,7 +455,6 @@ func (gq *GroupQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*
|
||||||
init(nodes[i])
|
init(nodes[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
query.withFKs = true
|
|
||||||
if len(query.ctx.Fields) > 0 {
|
if len(query.ctx.Fields) > 0 {
|
||||||
query.ctx.AppendFieldOnce(user.FieldGroupUsers)
|
query.ctx.AppendFieldOnce(user.FieldGroupUsers)
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -398,7 +398,6 @@ var (
|
||||||
{Name: "avatar", Type: field.TypeString, Nullable: true},
|
{Name: "avatar", Type: field.TypeString, Nullable: true},
|
||||||
{Name: "settings", Type: field.TypeJSON, Nullable: true},
|
{Name: "settings", Type: field.TypeJSON, Nullable: true},
|
||||||
{Name: "group_users", Type: field.TypeInt},
|
{Name: "group_users", Type: field.TypeInt},
|
||||||
{Name: "storage_policy_users", Type: field.TypeInt, Nullable: true},
|
|
||||||
}
|
}
|
||||||
// UsersTable holds the schema information for the "users" table.
|
// UsersTable holds the schema information for the "users" table.
|
||||||
UsersTable = &schema.Table{
|
UsersTable = &schema.Table{
|
||||||
|
@ -412,12 +411,6 @@ var (
|
||||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||||
OnDelete: schema.NoAction,
|
OnDelete: schema.NoAction,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Symbol: "users_storage_policies_users",
|
|
||||||
Columns: []*schema.Column{UsersColumns[13]},
|
|
||||||
RefColumns: []*schema.Column{StoragePoliciesColumns[0]},
|
|
||||||
OnDelete: schema.SetNull,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// FileEntitiesColumns holds the columns for the "file_entities" table.
|
// FileEntitiesColumns holds the columns for the "file_entities" table.
|
||||||
|
@ -480,7 +473,6 @@ func init() {
|
||||||
StoragePoliciesTable.ForeignKeys[0].RefTable = NodesTable
|
StoragePoliciesTable.ForeignKeys[0].RefTable = NodesTable
|
||||||
TasksTable.ForeignKeys[0].RefTable = UsersTable
|
TasksTable.ForeignKeys[0].RefTable = UsersTable
|
||||||
UsersTable.ForeignKeys[0].RefTable = GroupsTable
|
UsersTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
UsersTable.ForeignKeys[1].RefTable = StoragePoliciesTable
|
|
||||||
FileEntitiesTable.ForeignKeys[0].RefTable = FilesTable
|
FileEntitiesTable.ForeignKeys[0].RefTable = FilesTable
|
||||||
FileEntitiesTable.ForeignKeys[1].RefTable = EntitiesTable
|
FileEntitiesTable.ForeignKeys[1].RefTable = EntitiesTable
|
||||||
}
|
}
|
||||||
|
|
|
@ -9975,9 +9975,6 @@ type StoragePolicyMutation struct {
|
||||||
file_name_rule *string
|
file_name_rule *string
|
||||||
settings **types.PolicySetting
|
settings **types.PolicySetting
|
||||||
clearedFields map[string]struct{}
|
clearedFields map[string]struct{}
|
||||||
users map[int]struct{}
|
|
||||||
removedusers map[int]struct{}
|
|
||||||
clearedusers bool
|
|
||||||
groups map[int]struct{}
|
groups map[int]struct{}
|
||||||
removedgroups map[int]struct{}
|
removedgroups map[int]struct{}
|
||||||
clearedgroups bool
|
clearedgroups bool
|
||||||
|
@ -10796,60 +10793,6 @@ func (m *StoragePolicyMutation) ResetNodeID() {
|
||||||
delete(m.clearedFields, storagepolicy.FieldNodeID)
|
delete(m.clearedFields, storagepolicy.FieldNodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserIDs adds the "users" edge to the User entity by ids.
|
|
||||||
func (m *StoragePolicyMutation) AddUserIDs(ids ...int) {
|
|
||||||
if m.users == nil {
|
|
||||||
m.users = make(map[int]struct{})
|
|
||||||
}
|
|
||||||
for i := range ids {
|
|
||||||
m.users[ids[i]] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearUsers clears the "users" edge to the User entity.
|
|
||||||
func (m *StoragePolicyMutation) ClearUsers() {
|
|
||||||
m.clearedusers = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsersCleared reports if the "users" edge to the User entity was cleared.
|
|
||||||
func (m *StoragePolicyMutation) UsersCleared() bool {
|
|
||||||
return m.clearedusers
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveUserIDs removes the "users" edge to the User entity by IDs.
|
|
||||||
func (m *StoragePolicyMutation) RemoveUserIDs(ids ...int) {
|
|
||||||
if m.removedusers == nil {
|
|
||||||
m.removedusers = make(map[int]struct{})
|
|
||||||
}
|
|
||||||
for i := range ids {
|
|
||||||
delete(m.users, ids[i])
|
|
||||||
m.removedusers[ids[i]] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemovedUsers returns the removed IDs of the "users" edge to the User entity.
|
|
||||||
func (m *StoragePolicyMutation) RemovedUsersIDs() (ids []int) {
|
|
||||||
for id := range m.removedusers {
|
|
||||||
ids = append(ids, id)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsersIDs returns the "users" edge IDs in the mutation.
|
|
||||||
func (m *StoragePolicyMutation) UsersIDs() (ids []int) {
|
|
||||||
for id := range m.users {
|
|
||||||
ids = append(ids, id)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetUsers resets all changes to the "users" edge.
|
|
||||||
func (m *StoragePolicyMutation) ResetUsers() {
|
|
||||||
m.users = nil
|
|
||||||
m.clearedusers = false
|
|
||||||
m.removedusers = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddGroupIDs adds the "groups" edge to the Group entity by ids.
|
// AddGroupIDs adds the "groups" edge to the Group entity by ids.
|
||||||
func (m *StoragePolicyMutation) AddGroupIDs(ids ...int) {
|
func (m *StoragePolicyMutation) AddGroupIDs(ids ...int) {
|
||||||
if m.groups == nil {
|
if m.groups == nil {
|
||||||
|
@ -11494,10 +11437,7 @@ func (m *StoragePolicyMutation) ResetField(name string) error {
|
||||||
|
|
||||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||||
func (m *StoragePolicyMutation) AddedEdges() []string {
|
func (m *StoragePolicyMutation) AddedEdges() []string {
|
||||||
edges := make([]string, 0, 5)
|
edges := make([]string, 0, 4)
|
||||||
if m.users != nil {
|
|
||||||
edges = append(edges, storagepolicy.EdgeUsers)
|
|
||||||
}
|
|
||||||
if m.groups != nil {
|
if m.groups != nil {
|
||||||
edges = append(edges, storagepolicy.EdgeGroups)
|
edges = append(edges, storagepolicy.EdgeGroups)
|
||||||
}
|
}
|
||||||
|
@ -11517,12 +11457,6 @@ func (m *StoragePolicyMutation) AddedEdges() []string {
|
||||||
// name in this mutation.
|
// name in this mutation.
|
||||||
func (m *StoragePolicyMutation) AddedIDs(name string) []ent.Value {
|
func (m *StoragePolicyMutation) AddedIDs(name string) []ent.Value {
|
||||||
switch name {
|
switch name {
|
||||||
case storagepolicy.EdgeUsers:
|
|
||||||
ids := make([]ent.Value, 0, len(m.users))
|
|
||||||
for id := range m.users {
|
|
||||||
ids = append(ids, id)
|
|
||||||
}
|
|
||||||
return ids
|
|
||||||
case storagepolicy.EdgeGroups:
|
case storagepolicy.EdgeGroups:
|
||||||
ids := make([]ent.Value, 0, len(m.groups))
|
ids := make([]ent.Value, 0, len(m.groups))
|
||||||
for id := range m.groups {
|
for id := range m.groups {
|
||||||
|
@ -11551,10 +11485,7 @@ func (m *StoragePolicyMutation) AddedIDs(name string) []ent.Value {
|
||||||
|
|
||||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||||
func (m *StoragePolicyMutation) RemovedEdges() []string {
|
func (m *StoragePolicyMutation) RemovedEdges() []string {
|
||||||
edges := make([]string, 0, 5)
|
edges := make([]string, 0, 4)
|
||||||
if m.removedusers != nil {
|
|
||||||
edges = append(edges, storagepolicy.EdgeUsers)
|
|
||||||
}
|
|
||||||
if m.removedgroups != nil {
|
if m.removedgroups != nil {
|
||||||
edges = append(edges, storagepolicy.EdgeGroups)
|
edges = append(edges, storagepolicy.EdgeGroups)
|
||||||
}
|
}
|
||||||
|
@ -11571,12 +11502,6 @@ func (m *StoragePolicyMutation) RemovedEdges() []string {
|
||||||
// the given name in this mutation.
|
// the given name in this mutation.
|
||||||
func (m *StoragePolicyMutation) RemovedIDs(name string) []ent.Value {
|
func (m *StoragePolicyMutation) RemovedIDs(name string) []ent.Value {
|
||||||
switch name {
|
switch name {
|
||||||
case storagepolicy.EdgeUsers:
|
|
||||||
ids := make([]ent.Value, 0, len(m.removedusers))
|
|
||||||
for id := range m.removedusers {
|
|
||||||
ids = append(ids, id)
|
|
||||||
}
|
|
||||||
return ids
|
|
||||||
case storagepolicy.EdgeGroups:
|
case storagepolicy.EdgeGroups:
|
||||||
ids := make([]ent.Value, 0, len(m.removedgroups))
|
ids := make([]ent.Value, 0, len(m.removedgroups))
|
||||||
for id := range m.removedgroups {
|
for id := range m.removedgroups {
|
||||||
|
@ -11601,10 +11526,7 @@ func (m *StoragePolicyMutation) RemovedIDs(name string) []ent.Value {
|
||||||
|
|
||||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||||
func (m *StoragePolicyMutation) ClearedEdges() []string {
|
func (m *StoragePolicyMutation) ClearedEdges() []string {
|
||||||
edges := make([]string, 0, 5)
|
edges := make([]string, 0, 4)
|
||||||
if m.clearedusers {
|
|
||||||
edges = append(edges, storagepolicy.EdgeUsers)
|
|
||||||
}
|
|
||||||
if m.clearedgroups {
|
if m.clearedgroups {
|
||||||
edges = append(edges, storagepolicy.EdgeGroups)
|
edges = append(edges, storagepolicy.EdgeGroups)
|
||||||
}
|
}
|
||||||
|
@ -11624,8 +11546,6 @@ func (m *StoragePolicyMutation) ClearedEdges() []string {
|
||||||
// was cleared in this mutation.
|
// was cleared in this mutation.
|
||||||
func (m *StoragePolicyMutation) EdgeCleared(name string) bool {
|
func (m *StoragePolicyMutation) EdgeCleared(name string) bool {
|
||||||
switch name {
|
switch name {
|
||||||
case storagepolicy.EdgeUsers:
|
|
||||||
return m.clearedusers
|
|
||||||
case storagepolicy.EdgeGroups:
|
case storagepolicy.EdgeGroups:
|
||||||
return m.clearedgroups
|
return m.clearedgroups
|
||||||
case storagepolicy.EdgeFiles:
|
case storagepolicy.EdgeFiles:
|
||||||
|
@ -11653,9 +11573,6 @@ func (m *StoragePolicyMutation) ClearEdge(name string) error {
|
||||||
// It returns an error if the edge is not defined in the schema.
|
// It returns an error if the edge is not defined in the schema.
|
||||||
func (m *StoragePolicyMutation) ResetEdge(name string) error {
|
func (m *StoragePolicyMutation) ResetEdge(name string) error {
|
||||||
switch name {
|
switch name {
|
||||||
case storagepolicy.EdgeUsers:
|
|
||||||
m.ResetUsers()
|
|
||||||
return nil
|
|
||||||
case storagepolicy.EdgeGroups:
|
case storagepolicy.EdgeGroups:
|
||||||
m.ResetGroups()
|
m.ResetGroups()
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -47,7 +47,6 @@ func (StoragePolicy) Mixin() []ent.Mixin {
|
||||||
|
|
||||||
func (StoragePolicy) Edges() []ent.Edge {
|
func (StoragePolicy) Edges() []ent.Edge {
|
||||||
return []ent.Edge{
|
return []ent.Edge{
|
||||||
edge.To("users", User.Type),
|
|
||||||
edge.To("groups", Group.Type),
|
edge.To("groups", Group.Type),
|
||||||
edge.To("files", File.Type),
|
edge.To("files", File.Type),
|
||||||
edge.To("entities", Entity.Type),
|
edge.To("entities", Entity.Type),
|
||||||
|
|
|
@ -58,8 +58,6 @@ type StoragePolicy struct {
|
||||||
|
|
||||||
// StoragePolicyEdges holds the relations/edges for other nodes in the graph.
|
// StoragePolicyEdges holds the relations/edges for other nodes in the graph.
|
||||||
type StoragePolicyEdges struct {
|
type StoragePolicyEdges struct {
|
||||||
// Users holds the value of the users edge.
|
|
||||||
Users []*User `json:"users,omitempty"`
|
|
||||||
// Groups holds the value of the groups edge.
|
// Groups holds the value of the groups edge.
|
||||||
Groups []*Group `json:"groups,omitempty"`
|
Groups []*Group `json:"groups,omitempty"`
|
||||||
// Files holds the value of the files edge.
|
// Files holds the value of the files edge.
|
||||||
|
@ -70,22 +68,13 @@ type StoragePolicyEdges struct {
|
||||||
Node *Node `json:"node,omitempty"`
|
Node *Node `json:"node,omitempty"`
|
||||||
// loadedTypes holds the information for reporting if a
|
// loadedTypes holds the information for reporting if a
|
||||||
// type was loaded (or requested) in eager-loading or not.
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
loadedTypes [5]bool
|
loadedTypes [4]bool
|
||||||
}
|
|
||||||
|
|
||||||
// UsersOrErr returns the Users value or an error if the edge
|
|
||||||
// was not loaded in eager-loading.
|
|
||||||
func (e StoragePolicyEdges) UsersOrErr() ([]*User, error) {
|
|
||||||
if e.loadedTypes[0] {
|
|
||||||
return e.Users, nil
|
|
||||||
}
|
|
||||||
return nil, &NotLoadedError{edge: "users"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupsOrErr returns the Groups value or an error if the edge
|
// GroupsOrErr returns the Groups value or an error if the edge
|
||||||
// was not loaded in eager-loading.
|
// was not loaded in eager-loading.
|
||||||
func (e StoragePolicyEdges) GroupsOrErr() ([]*Group, error) {
|
func (e StoragePolicyEdges) GroupsOrErr() ([]*Group, error) {
|
||||||
if e.loadedTypes[1] {
|
if e.loadedTypes[0] {
|
||||||
return e.Groups, nil
|
return e.Groups, nil
|
||||||
}
|
}
|
||||||
return nil, &NotLoadedError{edge: "groups"}
|
return nil, &NotLoadedError{edge: "groups"}
|
||||||
|
@ -94,7 +83,7 @@ func (e StoragePolicyEdges) GroupsOrErr() ([]*Group, error) {
|
||||||
// FilesOrErr returns the Files value or an error if the edge
|
// FilesOrErr returns the Files value or an error if the edge
|
||||||
// was not loaded in eager-loading.
|
// was not loaded in eager-loading.
|
||||||
func (e StoragePolicyEdges) FilesOrErr() ([]*File, error) {
|
func (e StoragePolicyEdges) FilesOrErr() ([]*File, error) {
|
||||||
if e.loadedTypes[2] {
|
if e.loadedTypes[1] {
|
||||||
return e.Files, nil
|
return e.Files, nil
|
||||||
}
|
}
|
||||||
return nil, &NotLoadedError{edge: "files"}
|
return nil, &NotLoadedError{edge: "files"}
|
||||||
|
@ -103,7 +92,7 @@ func (e StoragePolicyEdges) FilesOrErr() ([]*File, error) {
|
||||||
// EntitiesOrErr returns the Entities value or an error if the edge
|
// EntitiesOrErr returns the Entities value or an error if the edge
|
||||||
// was not loaded in eager-loading.
|
// was not loaded in eager-loading.
|
||||||
func (e StoragePolicyEdges) EntitiesOrErr() ([]*Entity, error) {
|
func (e StoragePolicyEdges) EntitiesOrErr() ([]*Entity, error) {
|
||||||
if e.loadedTypes[3] {
|
if e.loadedTypes[2] {
|
||||||
return e.Entities, nil
|
return e.Entities, nil
|
||||||
}
|
}
|
||||||
return nil, &NotLoadedError{edge: "entities"}
|
return nil, &NotLoadedError{edge: "entities"}
|
||||||
|
@ -112,7 +101,7 @@ func (e StoragePolicyEdges) EntitiesOrErr() ([]*Entity, error) {
|
||||||
// NodeOrErr returns the Node value or an error if the edge
|
// NodeOrErr returns the Node value or an error if the edge
|
||||||
// was not loaded in eager-loading, or loaded but was not found.
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
func (e StoragePolicyEdges) NodeOrErr() (*Node, error) {
|
func (e StoragePolicyEdges) NodeOrErr() (*Node, error) {
|
||||||
if e.loadedTypes[4] {
|
if e.loadedTypes[3] {
|
||||||
if e.Node == nil {
|
if e.Node == nil {
|
||||||
// Edge was loaded but was not found.
|
// Edge was loaded but was not found.
|
||||||
return nil, &NotFoundError{label: node.Label}
|
return nil, &NotFoundError{label: node.Label}
|
||||||
|
@ -264,11 +253,6 @@ func (sp *StoragePolicy) Value(name string) (ent.Value, error) {
|
||||||
return sp.selectValues.Get(name)
|
return sp.selectValues.Get(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryUsers queries the "users" edge of the StoragePolicy entity.
|
|
||||||
func (sp *StoragePolicy) QueryUsers() *UserQuery {
|
|
||||||
return NewStoragePolicyClient(sp.config).QueryUsers(sp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGroups queries the "groups" edge of the StoragePolicy entity.
|
// QueryGroups queries the "groups" edge of the StoragePolicy entity.
|
||||||
func (sp *StoragePolicy) QueryGroups() *GroupQuery {
|
func (sp *StoragePolicy) QueryGroups() *GroupQuery {
|
||||||
return NewStoragePolicyClient(sp.config).QueryGroups(sp)
|
return NewStoragePolicyClient(sp.config).QueryGroups(sp)
|
||||||
|
@ -362,34 +346,28 @@ func (sp *StoragePolicy) String() string {
|
||||||
return builder.String()
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUsers manually set the edge as loaded state.
|
|
||||||
func (e *StoragePolicy) SetUsers(v []*User) {
|
|
||||||
e.Edges.Users = v
|
|
||||||
e.Edges.loadedTypes[0] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetGroups manually set the edge as loaded state.
|
// SetGroups manually set the edge as loaded state.
|
||||||
func (e *StoragePolicy) SetGroups(v []*Group) {
|
func (e *StoragePolicy) SetGroups(v []*Group) {
|
||||||
e.Edges.Groups = v
|
e.Edges.Groups = v
|
||||||
e.Edges.loadedTypes[1] = true
|
e.Edges.loadedTypes[0] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFiles manually set the edge as loaded state.
|
// SetFiles manually set the edge as loaded state.
|
||||||
func (e *StoragePolicy) SetFiles(v []*File) {
|
func (e *StoragePolicy) SetFiles(v []*File) {
|
||||||
e.Edges.Files = v
|
e.Edges.Files = v
|
||||||
e.Edges.loadedTypes[2] = true
|
e.Edges.loadedTypes[1] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEntities manually set the edge as loaded state.
|
// SetEntities manually set the edge as loaded state.
|
||||||
func (e *StoragePolicy) SetEntities(v []*Entity) {
|
func (e *StoragePolicy) SetEntities(v []*Entity) {
|
||||||
e.Edges.Entities = v
|
e.Edges.Entities = v
|
||||||
e.Edges.loadedTypes[3] = true
|
e.Edges.loadedTypes[2] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNode manually set the edge as loaded state.
|
// SetNode manually set the edge as loaded state.
|
||||||
func (e *StoragePolicy) SetNode(v *Node) {
|
func (e *StoragePolicy) SetNode(v *Node) {
|
||||||
e.Edges.Node = v
|
e.Edges.Node = v
|
||||||
e.Edges.loadedTypes[4] = true
|
e.Edges.loadedTypes[3] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoragePolicies is a parsable slice of StoragePolicy.
|
// StoragePolicies is a parsable slice of StoragePolicy.
|
||||||
|
|
|
@ -46,8 +46,6 @@ const (
|
||||||
FieldSettings = "settings"
|
FieldSettings = "settings"
|
||||||
// FieldNodeID holds the string denoting the node_id field in the database.
|
// FieldNodeID holds the string denoting the node_id field in the database.
|
||||||
FieldNodeID = "node_id"
|
FieldNodeID = "node_id"
|
||||||
// EdgeUsers holds the string denoting the users edge name in mutations.
|
|
||||||
EdgeUsers = "users"
|
|
||||||
// EdgeGroups holds the string denoting the groups edge name in mutations.
|
// EdgeGroups holds the string denoting the groups edge name in mutations.
|
||||||
EdgeGroups = "groups"
|
EdgeGroups = "groups"
|
||||||
// EdgeFiles holds the string denoting the files edge name in mutations.
|
// EdgeFiles holds the string denoting the files edge name in mutations.
|
||||||
|
@ -58,13 +56,6 @@ const (
|
||||||
EdgeNode = "node"
|
EdgeNode = "node"
|
||||||
// Table holds the table name of the storagepolicy in the database.
|
// Table holds the table name of the storagepolicy in the database.
|
||||||
Table = "storage_policies"
|
Table = "storage_policies"
|
||||||
// UsersTable is the table that holds the users relation/edge.
|
|
||||||
UsersTable = "users"
|
|
||||||
// UsersInverseTable is the table name for the User entity.
|
|
||||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
|
||||||
UsersInverseTable = "users"
|
|
||||||
// UsersColumn is the table column denoting the users relation/edge.
|
|
||||||
UsersColumn = "storage_policy_users"
|
|
||||||
// GroupsTable is the table that holds the groups relation/edge.
|
// GroupsTable is the table that holds the groups relation/edge.
|
||||||
GroupsTable = "groups"
|
GroupsTable = "groups"
|
||||||
// GroupsInverseTable is the table name for the Group entity.
|
// GroupsInverseTable is the table name for the Group entity.
|
||||||
|
@ -221,20 +212,6 @@ func ByNodeID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return sql.OrderByField(FieldNodeID, opts...).ToFunc()
|
return sql.OrderByField(FieldNodeID, opts...).ToFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByUsersCount orders the results by users count.
|
|
||||||
func ByUsersCount(opts ...sql.OrderTermOption) OrderOption {
|
|
||||||
return func(s *sql.Selector) {
|
|
||||||
sqlgraph.OrderByNeighborsCount(s, newUsersStep(), opts...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByUsers orders the results by users terms.
|
|
||||||
func ByUsers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
|
||||||
return func(s *sql.Selector) {
|
|
||||||
sqlgraph.OrderByNeighborTerms(s, newUsersStep(), append([]sql.OrderTerm{term}, terms...)...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByGroupsCount orders the results by groups count.
|
// ByGroupsCount orders the results by groups count.
|
||||||
func ByGroupsCount(opts ...sql.OrderTermOption) OrderOption {
|
func ByGroupsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
return func(s *sql.Selector) {
|
return func(s *sql.Selector) {
|
||||||
|
@ -283,13 +260,6 @@ func ByNodeField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
sqlgraph.OrderByNeighborTerms(s, newNodeStep(), sql.OrderByField(field, opts...))
|
sqlgraph.OrderByNeighborTerms(s, newNodeStep(), sql.OrderByField(field, opts...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func newUsersStep() *sqlgraph.Step {
|
|
||||||
return sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(Table, FieldID),
|
|
||||||
sqlgraph.To(UsersInverseTable, FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, UsersTable, UsersColumn),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
func newGroupsStep() *sqlgraph.Step {
|
func newGroupsStep() *sqlgraph.Step {
|
||||||
return sqlgraph.NewStep(
|
return sqlgraph.NewStep(
|
||||||
sqlgraph.From(Table, FieldID),
|
sqlgraph.From(Table, FieldID),
|
||||||
|
|
|
@ -945,29 +945,6 @@ func NodeIDNotNil() predicate.StoragePolicy {
|
||||||
return predicate.StoragePolicy(sql.FieldNotNull(FieldNodeID))
|
return predicate.StoragePolicy(sql.FieldNotNull(FieldNodeID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasUsers applies the HasEdge predicate on the "users" edge.
|
|
||||||
func HasUsers() predicate.StoragePolicy {
|
|
||||||
return predicate.StoragePolicy(func(s *sql.Selector) {
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(Table, FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, UsersTable, UsersColumn),
|
|
||||||
)
|
|
||||||
sqlgraph.HasNeighbors(s, step)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasUsersWith applies the HasEdge predicate on the "users" edge with a given conditions (other predicates).
|
|
||||||
func HasUsersWith(preds ...predicate.User) predicate.StoragePolicy {
|
|
||||||
return predicate.StoragePolicy(func(s *sql.Selector) {
|
|
||||||
step := newUsersStep()
|
|
||||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
|
||||||
for _, p := range preds {
|
|
||||||
p(s)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasGroups applies the HasEdge predicate on the "groups" edge.
|
// HasGroups applies the HasEdge predicate on the "groups" edge.
|
||||||
func HasGroups() predicate.StoragePolicy {
|
func HasGroups() predicate.StoragePolicy {
|
||||||
return predicate.StoragePolicy(func(s *sql.Selector) {
|
return predicate.StoragePolicy(func(s *sql.Selector) {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/group"
|
"github.com/cloudreve/Cloudreve/v4/ent/group"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/node"
|
"github.com/cloudreve/Cloudreve/v4/ent/node"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -214,21 +213,6 @@ func (spc *StoragePolicyCreate) SetNillableNodeID(i *int) *StoragePolicyCreate {
|
||||||
return spc
|
return spc
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
|
||||||
func (spc *StoragePolicyCreate) AddUserIDs(ids ...int) *StoragePolicyCreate {
|
|
||||||
spc.mutation.AddUserIDs(ids...)
|
|
||||||
return spc
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUsers adds the "users" edges to the User entity.
|
|
||||||
func (spc *StoragePolicyCreate) AddUsers(u ...*User) *StoragePolicyCreate {
|
|
||||||
ids := make([]int, len(u))
|
|
||||||
for i := range u {
|
|
||||||
ids[i] = u[i].ID
|
|
||||||
}
|
|
||||||
return spc.AddUserIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
||||||
func (spc *StoragePolicyCreate) AddGroupIDs(ids ...int) *StoragePolicyCreate {
|
func (spc *StoragePolicyCreate) AddGroupIDs(ids ...int) *StoragePolicyCreate {
|
||||||
spc.mutation.AddGroupIDs(ids...)
|
spc.mutation.AddGroupIDs(ids...)
|
||||||
|
@ -441,22 +425,6 @@ func (spc *StoragePolicyCreate) createSpec() (*StoragePolicy, *sqlgraph.CreateSp
|
||||||
_spec.SetField(storagepolicy.FieldSettings, field.TypeJSON, value)
|
_spec.SetField(storagepolicy.FieldSettings, field.TypeJSON, value)
|
||||||
_node.Settings = value
|
_node.Settings = value
|
||||||
}
|
}
|
||||||
if nodes := spc.mutation.UsersIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
|
||||||
}
|
|
||||||
if nodes := spc.mutation.GroupsIDs(); len(nodes) > 0 {
|
if nodes := spc.mutation.GroupsIDs(); len(nodes) > 0 {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/node"
|
"github.com/cloudreve/Cloudreve/v4/ent/node"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StoragePolicyQuery is the builder for querying StoragePolicy entities.
|
// StoragePolicyQuery is the builder for querying StoragePolicy entities.
|
||||||
|
@ -27,7 +26,6 @@ type StoragePolicyQuery struct {
|
||||||
order []storagepolicy.OrderOption
|
order []storagepolicy.OrderOption
|
||||||
inters []Interceptor
|
inters []Interceptor
|
||||||
predicates []predicate.StoragePolicy
|
predicates []predicate.StoragePolicy
|
||||||
withUsers *UserQuery
|
|
||||||
withGroups *GroupQuery
|
withGroups *GroupQuery
|
||||||
withFiles *FileQuery
|
withFiles *FileQuery
|
||||||
withEntities *EntityQuery
|
withEntities *EntityQuery
|
||||||
|
@ -68,28 +66,6 @@ func (spq *StoragePolicyQuery) Order(o ...storagepolicy.OrderOption) *StoragePol
|
||||||
return spq
|
return spq
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryUsers chains the current query on the "users" edge.
|
|
||||||
func (spq *StoragePolicyQuery) QueryUsers() *UserQuery {
|
|
||||||
query := (&UserClient{config: spq.config}).Query()
|
|
||||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
||||||
if err := spq.prepareQuery(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
selector := spq.sqlQuery(ctx)
|
|
||||||
if err := selector.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(storagepolicy.Table, storagepolicy.FieldID, selector),
|
|
||||||
sqlgraph.To(user.Table, user.FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, storagepolicy.UsersTable, storagepolicy.UsersColumn),
|
|
||||||
)
|
|
||||||
fromU = sqlgraph.SetNeighbors(spq.driver.Dialect(), step)
|
|
||||||
return fromU, nil
|
|
||||||
}
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryGroups chains the current query on the "groups" edge.
|
// QueryGroups chains the current query on the "groups" edge.
|
||||||
func (spq *StoragePolicyQuery) QueryGroups() *GroupQuery {
|
func (spq *StoragePolicyQuery) QueryGroups() *GroupQuery {
|
||||||
query := (&GroupClient{config: spq.config}).Query()
|
query := (&GroupClient{config: spq.config}).Query()
|
||||||
|
@ -370,7 +346,6 @@ func (spq *StoragePolicyQuery) Clone() *StoragePolicyQuery {
|
||||||
order: append([]storagepolicy.OrderOption{}, spq.order...),
|
order: append([]storagepolicy.OrderOption{}, spq.order...),
|
||||||
inters: append([]Interceptor{}, spq.inters...),
|
inters: append([]Interceptor{}, spq.inters...),
|
||||||
predicates: append([]predicate.StoragePolicy{}, spq.predicates...),
|
predicates: append([]predicate.StoragePolicy{}, spq.predicates...),
|
||||||
withUsers: spq.withUsers.Clone(),
|
|
||||||
withGroups: spq.withGroups.Clone(),
|
withGroups: spq.withGroups.Clone(),
|
||||||
withFiles: spq.withFiles.Clone(),
|
withFiles: spq.withFiles.Clone(),
|
||||||
withEntities: spq.withEntities.Clone(),
|
withEntities: spq.withEntities.Clone(),
|
||||||
|
@ -381,17 +356,6 @@ func (spq *StoragePolicyQuery) Clone() *StoragePolicyQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithUsers tells the query-builder to eager-load the nodes that are connected to
|
|
||||||
// the "users" edge. The optional arguments are used to configure the query builder of the edge.
|
|
||||||
func (spq *StoragePolicyQuery) WithUsers(opts ...func(*UserQuery)) *StoragePolicyQuery {
|
|
||||||
query := (&UserClient{config: spq.config}).Query()
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(query)
|
|
||||||
}
|
|
||||||
spq.withUsers = query
|
|
||||||
return spq
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithGroups tells the query-builder to eager-load the nodes that are connected to
|
// WithGroups tells the query-builder to eager-load the nodes that are connected to
|
||||||
// the "groups" edge. The optional arguments are used to configure the query builder of the edge.
|
// the "groups" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
func (spq *StoragePolicyQuery) WithGroups(opts ...func(*GroupQuery)) *StoragePolicyQuery {
|
func (spq *StoragePolicyQuery) WithGroups(opts ...func(*GroupQuery)) *StoragePolicyQuery {
|
||||||
|
@ -514,8 +478,7 @@ func (spq *StoragePolicyQuery) sqlAll(ctx context.Context, hooks ...queryHook) (
|
||||||
var (
|
var (
|
||||||
nodes = []*StoragePolicy{}
|
nodes = []*StoragePolicy{}
|
||||||
_spec = spq.querySpec()
|
_spec = spq.querySpec()
|
||||||
loadedTypes = [5]bool{
|
loadedTypes = [4]bool{
|
||||||
spq.withUsers != nil,
|
|
||||||
spq.withGroups != nil,
|
spq.withGroups != nil,
|
||||||
spq.withFiles != nil,
|
spq.withFiles != nil,
|
||||||
spq.withEntities != nil,
|
spq.withEntities != nil,
|
||||||
|
@ -540,13 +503,6 @@ func (spq *StoragePolicyQuery) sqlAll(ctx context.Context, hooks ...queryHook) (
|
||||||
if len(nodes) == 0 {
|
if len(nodes) == 0 {
|
||||||
return nodes, nil
|
return nodes, nil
|
||||||
}
|
}
|
||||||
if query := spq.withUsers; query != nil {
|
|
||||||
if err := spq.loadUsers(ctx, query, nodes,
|
|
||||||
func(n *StoragePolicy) { n.Edges.Users = []*User{} },
|
|
||||||
func(n *StoragePolicy, e *User) { n.Edges.Users = append(n.Edges.Users, e) }); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if query := spq.withGroups; query != nil {
|
if query := spq.withGroups; query != nil {
|
||||||
if err := spq.loadGroups(ctx, query, nodes,
|
if err := spq.loadGroups(ctx, query, nodes,
|
||||||
func(n *StoragePolicy) { n.Edges.Groups = []*Group{} },
|
func(n *StoragePolicy) { n.Edges.Groups = []*Group{} },
|
||||||
|
@ -577,37 +533,6 @@ func (spq *StoragePolicyQuery) sqlAll(ctx context.Context, hooks ...queryHook) (
|
||||||
return nodes, nil
|
return nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spq *StoragePolicyQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*StoragePolicy, init func(*StoragePolicy), assign func(*StoragePolicy, *User)) error {
|
|
||||||
fks := make([]driver.Value, 0, len(nodes))
|
|
||||||
nodeids := make(map[int]*StoragePolicy)
|
|
||||||
for i := range nodes {
|
|
||||||
fks = append(fks, nodes[i].ID)
|
|
||||||
nodeids[nodes[i].ID] = nodes[i]
|
|
||||||
if init != nil {
|
|
||||||
init(nodes[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query.withFKs = true
|
|
||||||
query.Where(predicate.User(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.InValues(s.C(storagepolicy.UsersColumn), fks...))
|
|
||||||
}))
|
|
||||||
neighbors, err := query.All(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, n := range neighbors {
|
|
||||||
fk := n.storage_policy_users
|
|
||||||
if fk == nil {
|
|
||||||
return fmt.Errorf(`foreign-key "storage_policy_users" is nil for node %v`, n.ID)
|
|
||||||
}
|
|
||||||
node, ok := nodeids[*fk]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf(`unexpected referenced foreign-key "storage_policy_users" returned %v for node %v`, *fk, n.ID)
|
|
||||||
}
|
|
||||||
assign(node, n)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (spq *StoragePolicyQuery) loadGroups(ctx context.Context, query *GroupQuery, nodes []*StoragePolicy, init func(*StoragePolicy), assign func(*StoragePolicy, *Group)) error {
|
func (spq *StoragePolicyQuery) loadGroups(ctx context.Context, query *GroupQuery, nodes []*StoragePolicy, init func(*StoragePolicy), assign func(*StoragePolicy, *Group)) error {
|
||||||
fks := make([]driver.Value, 0, len(nodes))
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
nodeids := make(map[int]*StoragePolicy)
|
nodeids := make(map[int]*StoragePolicy)
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/node"
|
"github.com/cloudreve/Cloudreve/v4/ent/node"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -287,21 +286,6 @@ func (spu *StoragePolicyUpdate) ClearNodeID() *StoragePolicyUpdate {
|
||||||
return spu
|
return spu
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
|
||||||
func (spu *StoragePolicyUpdate) AddUserIDs(ids ...int) *StoragePolicyUpdate {
|
|
||||||
spu.mutation.AddUserIDs(ids...)
|
|
||||||
return spu
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUsers adds the "users" edges to the User entity.
|
|
||||||
func (spu *StoragePolicyUpdate) AddUsers(u ...*User) *StoragePolicyUpdate {
|
|
||||||
ids := make([]int, len(u))
|
|
||||||
for i := range u {
|
|
||||||
ids[i] = u[i].ID
|
|
||||||
}
|
|
||||||
return spu.AddUserIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
||||||
func (spu *StoragePolicyUpdate) AddGroupIDs(ids ...int) *StoragePolicyUpdate {
|
func (spu *StoragePolicyUpdate) AddGroupIDs(ids ...int) *StoragePolicyUpdate {
|
||||||
spu.mutation.AddGroupIDs(ids...)
|
spu.mutation.AddGroupIDs(ids...)
|
||||||
|
@ -357,27 +341,6 @@ func (spu *StoragePolicyUpdate) Mutation() *StoragePolicyMutation {
|
||||||
return spu.mutation
|
return spu.mutation
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearUsers clears all "users" edges to the User entity.
|
|
||||||
func (spu *StoragePolicyUpdate) ClearUsers() *StoragePolicyUpdate {
|
|
||||||
spu.mutation.ClearUsers()
|
|
||||||
return spu
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveUserIDs removes the "users" edge to User entities by IDs.
|
|
||||||
func (spu *StoragePolicyUpdate) RemoveUserIDs(ids ...int) *StoragePolicyUpdate {
|
|
||||||
spu.mutation.RemoveUserIDs(ids...)
|
|
||||||
return spu
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveUsers removes "users" edges to User entities.
|
|
||||||
func (spu *StoragePolicyUpdate) RemoveUsers(u ...*User) *StoragePolicyUpdate {
|
|
||||||
ids := make([]int, len(u))
|
|
||||||
for i := range u {
|
|
||||||
ids[i] = u[i].ID
|
|
||||||
}
|
|
||||||
return spu.RemoveUserIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearGroups clears all "groups" edges to the Group entity.
|
// ClearGroups clears all "groups" edges to the Group entity.
|
||||||
func (spu *StoragePolicyUpdate) ClearGroups() *StoragePolicyUpdate {
|
func (spu *StoragePolicyUpdate) ClearGroups() *StoragePolicyUpdate {
|
||||||
spu.mutation.ClearGroups()
|
spu.mutation.ClearGroups()
|
||||||
|
@ -570,51 +533,6 @@ func (spu *StoragePolicyUpdate) sqlSave(ctx context.Context) (n int, err error)
|
||||||
if spu.mutation.SettingsCleared() {
|
if spu.mutation.SettingsCleared() {
|
||||||
_spec.ClearField(storagepolicy.FieldSettings, field.TypeJSON)
|
_spec.ClearField(storagepolicy.FieldSettings, field.TypeJSON)
|
||||||
}
|
}
|
||||||
if spu.mutation.UsersCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := spu.mutation.RemovedUsersIDs(); len(nodes) > 0 && !spu.mutation.UsersCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := spu.mutation.UsersIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
||||||
}
|
|
||||||
if spu.mutation.GroupsCleared() {
|
if spu.mutation.GroupsCleared() {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
@ -1052,21 +970,6 @@ func (spuo *StoragePolicyUpdateOne) ClearNodeID() *StoragePolicyUpdateOne {
|
||||||
return spuo
|
return spuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
|
||||||
func (spuo *StoragePolicyUpdateOne) AddUserIDs(ids ...int) *StoragePolicyUpdateOne {
|
|
||||||
spuo.mutation.AddUserIDs(ids...)
|
|
||||||
return spuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUsers adds the "users" edges to the User entity.
|
|
||||||
func (spuo *StoragePolicyUpdateOne) AddUsers(u ...*User) *StoragePolicyUpdateOne {
|
|
||||||
ids := make([]int, len(u))
|
|
||||||
for i := range u {
|
|
||||||
ids[i] = u[i].ID
|
|
||||||
}
|
|
||||||
return spuo.AddUserIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
||||||
func (spuo *StoragePolicyUpdateOne) AddGroupIDs(ids ...int) *StoragePolicyUpdateOne {
|
func (spuo *StoragePolicyUpdateOne) AddGroupIDs(ids ...int) *StoragePolicyUpdateOne {
|
||||||
spuo.mutation.AddGroupIDs(ids...)
|
spuo.mutation.AddGroupIDs(ids...)
|
||||||
|
@ -1122,27 +1025,6 @@ func (spuo *StoragePolicyUpdateOne) Mutation() *StoragePolicyMutation {
|
||||||
return spuo.mutation
|
return spuo.mutation
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearUsers clears all "users" edges to the User entity.
|
|
||||||
func (spuo *StoragePolicyUpdateOne) ClearUsers() *StoragePolicyUpdateOne {
|
|
||||||
spuo.mutation.ClearUsers()
|
|
||||||
return spuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveUserIDs removes the "users" edge to User entities by IDs.
|
|
||||||
func (spuo *StoragePolicyUpdateOne) RemoveUserIDs(ids ...int) *StoragePolicyUpdateOne {
|
|
||||||
spuo.mutation.RemoveUserIDs(ids...)
|
|
||||||
return spuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveUsers removes "users" edges to User entities.
|
|
||||||
func (spuo *StoragePolicyUpdateOne) RemoveUsers(u ...*User) *StoragePolicyUpdateOne {
|
|
||||||
ids := make([]int, len(u))
|
|
||||||
for i := range u {
|
|
||||||
ids[i] = u[i].ID
|
|
||||||
}
|
|
||||||
return spuo.RemoveUserIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearGroups clears all "groups" edges to the Group entity.
|
// ClearGroups clears all "groups" edges to the Group entity.
|
||||||
func (spuo *StoragePolicyUpdateOne) ClearGroups() *StoragePolicyUpdateOne {
|
func (spuo *StoragePolicyUpdateOne) ClearGroups() *StoragePolicyUpdateOne {
|
||||||
spuo.mutation.ClearGroups()
|
spuo.mutation.ClearGroups()
|
||||||
|
@ -1365,51 +1247,6 @@ func (spuo *StoragePolicyUpdateOne) sqlSave(ctx context.Context) (_node *Storage
|
||||||
if spuo.mutation.SettingsCleared() {
|
if spuo.mutation.SettingsCleared() {
|
||||||
_spec.ClearField(storagepolicy.FieldSettings, field.TypeJSON)
|
_spec.ClearField(storagepolicy.FieldSettings, field.TypeJSON)
|
||||||
}
|
}
|
||||||
if spuo.mutation.UsersCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := spuo.mutation.RemovedUsersIDs(); len(nodes) > 0 && !spuo.mutation.UsersCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := spuo.mutation.UsersIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: storagepolicy.UsersTable,
|
|
||||||
Columns: []string{storagepolicy.UsersColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
||||||
}
|
|
||||||
if spuo.mutation.GroupsCleared() {
|
if spuo.mutation.GroupsCleared() {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
|
14
ent/user.go
14
ent/user.go
|
@ -46,9 +46,8 @@ type User struct {
|
||||||
GroupUsers int `json:"group_users,omitempty"`
|
GroupUsers int `json:"group_users,omitempty"`
|
||||||
// Edges holds the relations/edges for other nodes in the graph.
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
// The values are being populated by the UserQuery when eager-loading is set.
|
// The values are being populated by the UserQuery when eager-loading is set.
|
||||||
Edges UserEdges `json:"edges"`
|
Edges UserEdges `json:"edges"`
|
||||||
storage_policy_users *int
|
selectValues sql.SelectValues
|
||||||
selectValues sql.SelectValues
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
@ -152,8 +151,6 @@ func (*User) scanValues(columns []string) ([]any, error) {
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldDeletedAt:
|
case user.FieldCreatedAt, user.FieldUpdatedAt, user.FieldDeletedAt:
|
||||||
values[i] = new(sql.NullTime)
|
values[i] = new(sql.NullTime)
|
||||||
case user.ForeignKeys[0]: // storage_policy_users
|
|
||||||
values[i] = new(sql.NullInt64)
|
|
||||||
default:
|
default:
|
||||||
values[i] = new(sql.UnknownType)
|
values[i] = new(sql.UnknownType)
|
||||||
}
|
}
|
||||||
|
@ -250,13 +247,6 @@ func (u *User) assignValues(columns []string, values []any) error {
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
u.GroupUsers = int(value.Int64)
|
u.GroupUsers = int(value.Int64)
|
||||||
}
|
}
|
||||||
case user.ForeignKeys[0]:
|
|
||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for edge-field storage_policy_users", value)
|
|
||||||
} else if value.Valid {
|
|
||||||
u.storage_policy_users = new(int)
|
|
||||||
*u.storage_policy_users = int(value.Int64)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
u.selectValues.Set(columns[i], values[i])
|
u.selectValues.Set(columns[i], values[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,12 +125,6 @@ var Columns = []string{
|
||||||
FieldGroupUsers,
|
FieldGroupUsers,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
|
|
||||||
// table and are not defined as standalone fields in the schema.
|
|
||||||
var ForeignKeys = []string{
|
|
||||||
"storage_policy_users",
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
func ValidColumn(column string) bool {
|
func ValidColumn(column string) bool {
|
||||||
for i := range Columns {
|
for i := range Columns {
|
||||||
|
@ -138,11 +132,6 @@ func ValidColumn(column string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range ForeignKeys {
|
|
||||||
if column == ForeignKeys[i] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ type UserQuery struct {
|
||||||
withPasskey *PasskeyQuery
|
withPasskey *PasskeyQuery
|
||||||
withTasks *TaskQuery
|
withTasks *TaskQuery
|
||||||
withEntities *EntityQuery
|
withEntities *EntityQuery
|
||||||
withFKs bool
|
|
||||||
// intermediate query (i.e. traversal path).
|
// intermediate query (i.e. traversal path).
|
||||||
sql *sql.Selector
|
sql *sql.Selector
|
||||||
path func(context.Context) (*sql.Selector, error)
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
@ -586,7 +585,6 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
||||||
func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||||
var (
|
var (
|
||||||
nodes = []*User{}
|
nodes = []*User{}
|
||||||
withFKs = uq.withFKs
|
|
||||||
_spec = uq.querySpec()
|
_spec = uq.querySpec()
|
||||||
loadedTypes = [7]bool{
|
loadedTypes = [7]bool{
|
||||||
uq.withGroup != nil,
|
uq.withGroup != nil,
|
||||||
|
@ -598,9 +596,6 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
||||||
uq.withEntities != nil,
|
uq.withEntities != nil,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if withFKs {
|
|
||||||
_spec.Node.Columns = append(_spec.Node.Columns, user.ForeignKeys...)
|
|
||||||
}
|
|
||||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
return (*User).scanValues(nil, columns)
|
return (*User).scanValues(nil, columns)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue