mirror of
https://github.com/cloudreve/cloudreve.git
synced 2025-12-15 10:04:01 +08:00
fix(dbfs): file modified_at should not be updated by ent
This commit is contained in:
@@ -1034,8 +1034,7 @@ func (c *FileClient) Hooks() []Hook {
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *FileClient) Interceptors() []Interceptor {
|
||||
inters := c.inters.File
|
||||
return append(inters[:len(inters):len(inters)], file.Interceptors[:]...)
|
||||
return c.inters.File
|
||||
}
|
||||
|
||||
func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) {
|
||||
|
||||
16
ent/file.go
16
ent/file.go
@@ -25,8 +25,6 @@ type File struct {
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// DeletedAt holds the value of the "deleted_at" field.
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type int `json:"type,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
@@ -171,7 +169,7 @@ func (*File) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullInt64)
|
||||
case file.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
case file.FieldCreatedAt, file.FieldUpdatedAt, file.FieldDeletedAt:
|
||||
case file.FieldCreatedAt, file.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -206,13 +204,6 @@ func (f *File) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
f.UpdatedAt = value.Time
|
||||
}
|
||||
case file.FieldDeletedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
||||
} else if value.Valid {
|
||||
f.DeletedAt = new(time.Time)
|
||||
*f.DeletedAt = value.Time
|
||||
}
|
||||
case file.FieldType:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
@@ -351,11 +342,6 @@ func (f *File) String() string {
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(f.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
if v := f.DeletedAt; v != nil {
|
||||
builder.WriteString("deleted_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", f.Type))
|
||||
builder.WriteString(", ")
|
||||
|
||||
@@ -19,8 +19,6 @@ const (
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
|
||||
FieldDeletedAt = "deleted_at"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
@@ -112,7 +110,6 @@ var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldDeletedAt,
|
||||
FieldType,
|
||||
FieldName,
|
||||
FieldOwnerID,
|
||||
@@ -146,14 +143,11 @@ func ValidColumn(column string) bool {
|
||||
//
|
||||
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
Interceptors [1]ent.Interceptor
|
||||
Hooks [1]ent.Hook
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DefaultSize holds the default value on creation for the "size" field.
|
||||
DefaultSize int64
|
||||
// DefaultIsSymbolic holds the default value on creation for the "is_symbolic" field.
|
||||
@@ -178,11 +172,6 @@ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDeletedAt orders the results by the deleted_at field.
|
||||
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
|
||||
@@ -65,11 +65,6 @@ func UpdatedAt(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
|
||||
func DeletedAt(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||
func Type(v int) predicate.File {
|
||||
return predicate.File(sql.FieldEQ(FieldType, v))
|
||||
@@ -190,56 +185,6 @@ func UpdatedAtLTE(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
|
||||
func DeletedAtEQ(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
|
||||
func DeletedAtNEQ(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldNEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtIn applies the In predicate on the "deleted_at" field.
|
||||
func DeletedAtIn(vs ...time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldIn(FieldDeletedAt, vs...))
|
||||
}
|
||||
|
||||
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
|
||||
func DeletedAtNotIn(vs ...time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldNotIn(FieldDeletedAt, vs...))
|
||||
}
|
||||
|
||||
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
|
||||
func DeletedAtGT(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldGT(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
|
||||
func DeletedAtGTE(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldGTE(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
|
||||
func DeletedAtLT(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldLT(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
|
||||
func DeletedAtLTE(v time.Time) predicate.File {
|
||||
return predicate.File(sql.FieldLTE(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
|
||||
func DeletedAtIsNil() predicate.File {
|
||||
return predicate.File(sql.FieldIsNull(FieldDeletedAt))
|
||||
}
|
||||
|
||||
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
|
||||
func DeletedAtNotNil() predicate.File {
|
||||
return predicate.File(sql.FieldNotNull(FieldDeletedAt))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v int) predicate.File {
|
||||
return predicate.File(sql.FieldEQ(FieldType, v))
|
||||
|
||||
@@ -57,20 +57,6 @@ func (fc *FileCreate) SetNillableUpdatedAt(t *time.Time) *FileCreate {
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (fc *FileCreate) SetDeletedAt(t time.Time) *FileCreate {
|
||||
fc.mutation.SetDeletedAt(t)
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (fc *FileCreate) SetNillableDeletedAt(t *time.Time) *FileCreate {
|
||||
if t != nil {
|
||||
fc.SetDeletedAt(*t)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (fc *FileCreate) SetType(i int) *FileCreate {
|
||||
fc.mutation.SetType(i)
|
||||
@@ -413,10 +399,6 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := fc.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
|
||||
_node.DeletedAt = &value
|
||||
}
|
||||
if value, ok := fc.mutation.GetType(); ok {
|
||||
_spec.SetField(file.FieldType, field.TypeInt, value)
|
||||
_node.Type = value
|
||||
@@ -636,24 +618,6 @@ func (u *FileUpsert) UpdateUpdatedAt() *FileUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (u *FileUpsert) SetDeletedAt(v time.Time) *FileUpsert {
|
||||
u.Set(file.FieldDeletedAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||
func (u *FileUpsert) UpdateDeletedAt() *FileUpsert {
|
||||
u.SetExcluded(file.FieldDeletedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (u *FileUpsert) ClearDeletedAt() *FileUpsert {
|
||||
u.SetNull(file.FieldDeletedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *FileUpsert) SetType(v int) *FileUpsert {
|
||||
u.Set(file.FieldType, v)
|
||||
@@ -863,27 +827,6 @@ func (u *FileUpsertOne) UpdateUpdatedAt() *FileUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (u *FileUpsertOne) SetDeletedAt(v time.Time) *FileUpsertOne {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
s.SetDeletedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||
func (u *FileUpsertOne) UpdateDeletedAt() *FileUpsertOne {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
s.UpdateDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (u *FileUpsertOne) ClearDeletedAt() *FileUpsertOne {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
s.ClearDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *FileUpsertOne) SetType(v int) *FileUpsertOne {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
@@ -1289,27 +1232,6 @@ func (u *FileUpsertBulk) UpdateUpdatedAt() *FileUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (u *FileUpsertBulk) SetDeletedAt(v time.Time) *FileUpsertBulk {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
s.SetDeletedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||
func (u *FileUpsertBulk) UpdateDeletedAt() *FileUpsertBulk {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
s.UpdateDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (u *FileUpsertBulk) ClearDeletedAt() *FileUpsertBulk {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
s.ClearDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *FileUpsertBulk) SetType(v int) *FileUpsertBulk {
|
||||
return u.Update(func(s *FileUpsert) {
|
||||
|
||||
@@ -41,26 +41,14 @@ func (fu *FileUpdate) SetUpdatedAt(t time.Time) *FileUpdate {
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (fu *FileUpdate) SetDeletedAt(t time.Time) *FileUpdate {
|
||||
fu.mutation.SetDeletedAt(t)
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (fu *FileUpdate) SetNillableDeletedAt(t *time.Time) *FileUpdate {
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (fu *FileUpdate) SetNillableUpdatedAt(t *time.Time) *FileUpdate {
|
||||
if t != nil {
|
||||
fu.SetDeletedAt(*t)
|
||||
fu.SetUpdatedAt(*t)
|
||||
}
|
||||
return fu
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (fu *FileUpdate) ClearDeletedAt() *FileUpdate {
|
||||
fu.mutation.ClearDeletedAt()
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (fu *FileUpdate) SetType(i int) *FileUpdate {
|
||||
fu.mutation.ResetType()
|
||||
@@ -472,9 +460,6 @@ func (fu *FileUpdate) RemoveDirectLinks(d ...*DirectLink) *FileUpdate {
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
|
||||
if err := fu.defaults(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks)
|
||||
}
|
||||
|
||||
@@ -500,18 +485,6 @@ func (fu *FileUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (fu *FileUpdate) defaults() error {
|
||||
if _, ok := fu.mutation.UpdatedAt(); !ok {
|
||||
if file.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized file.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := file.UpdateDefaultUpdatedAt()
|
||||
fu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (fu *FileUpdate) check() error {
|
||||
if _, ok := fu.mutation.OwnerID(); fu.mutation.OwnerCleared() && !ok {
|
||||
@@ -535,12 +508,6 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := fu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := fu.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
|
||||
}
|
||||
if fu.mutation.DeletedAtCleared() {
|
||||
_spec.ClearField(file.FieldDeletedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := fu.mutation.GetType(); ok {
|
||||
_spec.SetField(file.FieldType, field.TypeInt, value)
|
||||
}
|
||||
@@ -912,26 +879,14 @@ func (fuo *FileUpdateOne) SetUpdatedAt(t time.Time) *FileUpdateOne {
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (fuo *FileUpdateOne) SetDeletedAt(t time.Time) *FileUpdateOne {
|
||||
fuo.mutation.SetDeletedAt(t)
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (fuo *FileUpdateOne) SetNillableDeletedAt(t *time.Time) *FileUpdateOne {
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (fuo *FileUpdateOne) SetNillableUpdatedAt(t *time.Time) *FileUpdateOne {
|
||||
if t != nil {
|
||||
fuo.SetDeletedAt(*t)
|
||||
fuo.SetUpdatedAt(*t)
|
||||
}
|
||||
return fuo
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (fuo *FileUpdateOne) ClearDeletedAt() *FileUpdateOne {
|
||||
fuo.mutation.ClearDeletedAt()
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (fuo *FileUpdateOne) SetType(i int) *FileUpdateOne {
|
||||
fuo.mutation.ResetType()
|
||||
@@ -1356,9 +1311,6 @@ func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne
|
||||
|
||||
// Save executes the query and returns the updated File entity.
|
||||
func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) {
|
||||
if err := fuo.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks)
|
||||
}
|
||||
|
||||
@@ -1384,18 +1336,6 @@ func (fuo *FileUpdateOne) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (fuo *FileUpdateOne) defaults() error {
|
||||
if _, ok := fuo.mutation.UpdatedAt(); !ok {
|
||||
if file.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized file.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := file.UpdateDefaultUpdatedAt()
|
||||
fuo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (fuo *FileUpdateOne) check() error {
|
||||
if _, ok := fuo.mutation.OwnerID(); fuo.mutation.OwnerCleared() && !ok {
|
||||
@@ -1436,12 +1376,6 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error)
|
||||
if value, ok := fuo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := fuo.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(file.FieldDeletedAt, field.TypeTime, value)
|
||||
}
|
||||
if fuo.mutation.DeletedAtCleared() {
|
||||
_spec.ClearField(file.FieldDeletedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := fuo.mutation.GetType(); ok {
|
||||
_spec.SetField(file.FieldType, field.TypeInt, value)
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -107,7 +107,6 @@ var (
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
|
||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}},
|
||||
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"mysql": "datetime"}},
|
||||
{Name: "type", Type: field.TypeInt},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "size", Type: field.TypeInt64, Default: 0},
|
||||
@@ -126,19 +125,19 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "files_files_children",
|
||||
Columns: []*schema.Column{FilesColumns[10]},
|
||||
Columns: []*schema.Column{FilesColumns[9]},
|
||||
RefColumns: []*schema.Column{FilesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "files_storage_policies_files",
|
||||
Columns: []*schema.Column{FilesColumns[11]},
|
||||
Columns: []*schema.Column{FilesColumns[10]},
|
||||
RefColumns: []*schema.Column{StoragePoliciesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "files_users_files",
|
||||
Columns: []*schema.Column{FilesColumns[12]},
|
||||
Columns: []*schema.Column{FilesColumns[11]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
@@ -147,17 +146,17 @@ var (
|
||||
{
|
||||
Name: "file_file_children_name",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{FilesColumns[10], FilesColumns[5]},
|
||||
Columns: []*schema.Column{FilesColumns[9], FilesColumns[4]},
|
||||
},
|
||||
{
|
||||
Name: "file_file_children_type_updated_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{FilesColumns[10], FilesColumns[4], FilesColumns[2]},
|
||||
Columns: []*schema.Column{FilesColumns[9], FilesColumns[3], FilesColumns[2]},
|
||||
},
|
||||
{
|
||||
Name: "file_file_children_type_size",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{FilesColumns[10], FilesColumns[4], FilesColumns[6]},
|
||||
Columns: []*schema.Column{FilesColumns[9], FilesColumns[3], FilesColumns[5]},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2972,7 +2972,6 @@ type FileMutation struct {
|
||||
id *int
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
deleted_at *time.Time
|
||||
_type *int
|
||||
add_type *int
|
||||
name *string
|
||||
@@ -3179,55 +3178,6 @@ func (m *FileMutation) ResetUpdatedAt() {
|
||||
m.updated_at = nil
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (m *FileMutation) SetDeletedAt(t time.Time) {
|
||||
m.deleted_at = &t
|
||||
}
|
||||
|
||||
// DeletedAt returns the value of the "deleted_at" field in the mutation.
|
||||
func (m *FileMutation) DeletedAt() (r time.Time, exists bool) {
|
||||
v := m.deleted_at
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldDeletedAt returns the old "deleted_at" field's value of the File entity.
|
||||
// If the File object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *FileMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
|
||||
}
|
||||
return oldValue.DeletedAt, nil
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (m *FileMutation) ClearDeletedAt() {
|
||||
m.deleted_at = nil
|
||||
m.clearedFields[file.FieldDeletedAt] = struct{}{}
|
||||
}
|
||||
|
||||
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
|
||||
func (m *FileMutation) DeletedAtCleared() bool {
|
||||
_, ok := m.clearedFields[file.FieldDeletedAt]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetDeletedAt resets all changes to the "deleted_at" field.
|
||||
func (m *FileMutation) ResetDeletedAt() {
|
||||
m.deleted_at = nil
|
||||
delete(m.clearedFields, file.FieldDeletedAt)
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (m *FileMutation) SetType(i int) {
|
||||
m._type = &i
|
||||
@@ -4076,16 +4026,13 @@ func (m *FileMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *FileMutation) Fields() []string {
|
||||
fields := make([]string, 0, 12)
|
||||
fields := make([]string, 0, 11)
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, file.FieldCreatedAt)
|
||||
}
|
||||
if m.updated_at != nil {
|
||||
fields = append(fields, file.FieldUpdatedAt)
|
||||
}
|
||||
if m.deleted_at != nil {
|
||||
fields = append(fields, file.FieldDeletedAt)
|
||||
}
|
||||
if m._type != nil {
|
||||
fields = append(fields, file.FieldType)
|
||||
}
|
||||
@@ -4125,8 +4072,6 @@ func (m *FileMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.CreatedAt()
|
||||
case file.FieldUpdatedAt:
|
||||
return m.UpdatedAt()
|
||||
case file.FieldDeletedAt:
|
||||
return m.DeletedAt()
|
||||
case file.FieldType:
|
||||
return m.GetType()
|
||||
case file.FieldName:
|
||||
@@ -4158,8 +4103,6 @@ func (m *FileMutation) OldField(ctx context.Context, name string) (ent.Value, er
|
||||
return m.OldCreatedAt(ctx)
|
||||
case file.FieldUpdatedAt:
|
||||
return m.OldUpdatedAt(ctx)
|
||||
case file.FieldDeletedAt:
|
||||
return m.OldDeletedAt(ctx)
|
||||
case file.FieldType:
|
||||
return m.OldType(ctx)
|
||||
case file.FieldName:
|
||||
@@ -4201,13 +4144,6 @@ func (m *FileMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetUpdatedAt(v)
|
||||
return nil
|
||||
case file.FieldDeletedAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetDeletedAt(v)
|
||||
return nil
|
||||
case file.FieldType:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
@@ -4340,9 +4276,6 @@ func (m *FileMutation) AddField(name string, value ent.Value) error {
|
||||
// mutation.
|
||||
func (m *FileMutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(file.FieldDeletedAt) {
|
||||
fields = append(fields, file.FieldDeletedAt)
|
||||
}
|
||||
if m.FieldCleared(file.FieldPrimaryEntity) {
|
||||
fields = append(fields, file.FieldPrimaryEntity)
|
||||
}
|
||||
@@ -4369,9 +4302,6 @@ func (m *FileMutation) FieldCleared(name string) bool {
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *FileMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case file.FieldDeletedAt:
|
||||
m.ClearDeletedAt()
|
||||
return nil
|
||||
case file.FieldPrimaryEntity:
|
||||
m.ClearPrimaryEntity()
|
||||
return nil
|
||||
@@ -4398,9 +4328,6 @@ func (m *FileMutation) ResetField(name string) error {
|
||||
case file.FieldUpdatedAt:
|
||||
m.ResetUpdatedAt()
|
||||
return nil
|
||||
case file.FieldDeletedAt:
|
||||
m.ResetDeletedAt()
|
||||
return nil
|
||||
case file.FieldType:
|
||||
m.ResetType()
|
||||
return nil
|
||||
|
||||
@@ -87,31 +87,24 @@ func init() {
|
||||
entityDescReferenceCount := entityFields[3].Descriptor()
|
||||
// entity.DefaultReferenceCount holds the default value on creation for the reference_count field.
|
||||
entity.DefaultReferenceCount = entityDescReferenceCount.Default.(int)
|
||||
fileMixin := schema.File{}.Mixin()
|
||||
fileMixinHooks0 := fileMixin[0].Hooks()
|
||||
file.Hooks[0] = fileMixinHooks0[0]
|
||||
fileMixinInters0 := fileMixin[0].Interceptors()
|
||||
file.Interceptors[0] = fileMixinInters0[0]
|
||||
fileMixinFields0 := fileMixin[0].Fields()
|
||||
_ = fileMixinFields0
|
||||
fileHooks := schema.File{}.Hooks()
|
||||
file.Hooks[0] = fileHooks[0]
|
||||
fileFields := schema.File{}.Fields()
|
||||
_ = fileFields
|
||||
// fileDescCreatedAt is the schema descriptor for created_at field.
|
||||
fileDescCreatedAt := fileMixinFields0[0].Descriptor()
|
||||
fileDescCreatedAt := fileFields[0].Descriptor()
|
||||
// file.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
file.DefaultCreatedAt = fileDescCreatedAt.Default.(func() time.Time)
|
||||
// fileDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
fileDescUpdatedAt := fileMixinFields0[1].Descriptor()
|
||||
fileDescUpdatedAt := fileFields[1].Descriptor()
|
||||
// file.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
file.DefaultUpdatedAt = fileDescUpdatedAt.Default.(func() time.Time)
|
||||
// file.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
file.UpdateDefaultUpdatedAt = fileDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// fileDescSize is the schema descriptor for size field.
|
||||
fileDescSize := fileFields[3].Descriptor()
|
||||
fileDescSize := fileFields[5].Descriptor()
|
||||
// file.DefaultSize holds the default value on creation for the size field.
|
||||
file.DefaultSize = fileDescSize.Default.(int64)
|
||||
// fileDescIsSymbolic is the schema descriptor for is_symbolic field.
|
||||
fileDescIsSymbolic := fileFields[6].Descriptor()
|
||||
fileDescIsSymbolic := fileFields[8].Descriptor()
|
||||
// file.DefaultIsSymbolic holds the default value on creation for the is_symbolic field.
|
||||
file.DefaultIsSymbolic = fileDescIsSymbolic.Default.(bool)
|
||||
groupMixin := schema.Group{}.Mixin()
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/hook"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
)
|
||||
|
||||
@@ -16,6 +21,17 @@ type File struct {
|
||||
// Fields of the File.
|
||||
func (File) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Time("created_at").
|
||||
Immutable().
|
||||
Default(time.Now).
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "datetime",
|
||||
}),
|
||||
field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "datetime",
|
||||
}),
|
||||
field.Int("type"),
|
||||
field.String("name"),
|
||||
field.Int("owner_id"),
|
||||
@@ -66,8 +82,19 @@ func (File) Indexes() []ent.Index {
|
||||
}
|
||||
}
|
||||
|
||||
func (File) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
CommonMixin{},
|
||||
func (f File) Hooks() []ent.Hook {
|
||||
return []ent.Hook{
|
||||
hook.On(func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if s, ok := m.(interface{ SetUpdatedAt(time.Time) }); ok {
|
||||
_, set := m.Field("updated_at")
|
||||
if !set {
|
||||
s.SetUpdatedAt(time.Now())
|
||||
}
|
||||
}
|
||||
v, err := next.Mutate(ctx, m)
|
||||
return v, err
|
||||
})
|
||||
}, ent.OpUpdate|ent.OpUpdateOne),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user