refactor: use latest timestamp for created_at

This commit is contained in:
Bhunter 2025-01-10 12:49:30 +01:00
parent ffa9a27bb0
commit 3252c207bc
2 changed files with 1 additions and 5 deletions

View file

@ -21,6 +21,6 @@ type File struct {
ParentID sql.NullString `gorm:"type:uuid;index"`
Parts datatypes.JSONSlice[api.Part] `gorm:"type:jsonb"`
ChannelID *int64 `gorm:"type:bigint"`
CreatedAt time.Time `gorm:"autoCreateTime:false"`
CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
UpdatedAt time.Time `gorm:"autoUpdateTime:false"`
}

View file

@ -229,10 +229,8 @@ func (a *apiService) FilesCopy(ctx context.Context, req *api.FileCopy, params ap
dbFile.Category = string(file.Category)
if req.UpdatedAt.IsSet() && !req.UpdatedAt.Value.IsZero() {
dbFile.UpdatedAt = req.UpdatedAt.Value
dbFile.CreatedAt = req.UpdatedAt.Value
} else {
dbFile.UpdatedAt = time.Now().UTC()
dbFile.CreatedAt = time.Now().UTC()
}
if err := a.db.Create(&dbFile).Error; err != nil {
@ -316,10 +314,8 @@ func (a *apiService) FilesCreate(ctx context.Context, fileIn *api.File) (*api.Fi
fileDB.Encrypted = fileIn.Encrypted.Value
if fileIn.UpdatedAt.IsSet() && !fileIn.UpdatedAt.Value.IsZero() {
fileDB.UpdatedAt = fileIn.UpdatedAt.Value
fileDB.CreatedAt = fileIn.UpdatedAt.Value
} else {
fileDB.UpdatedAt = time.Now().UTC()
fileDB.CreatedAt = time.Now().UTC()
}
if err := a.db.Create(&fileDB).Error; err != nil {
if database.IsKeyConflictErr(err) {