Fix incorrectly formatted timestamps (#2918)

* Update updated_at when adding file to object
* Use models.SQLTimestamp for timestamps
* Add data massage to fix incorrect timestamps
This commit is contained in:
WithoutPants
2022-09-19 14:53:46 +10:00
committed by GitHub
parent 2564351265
commit 1207629a76
9 changed files with 175 additions and 46 deletions

View File

@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"path/filepath"
"time"
"github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/file"
@@ -28,14 +27,14 @@ const (
)
type imageRow struct {
ID int `db:"id" goqu:"skipinsert"`
Title zero.String `db:"title"`
Rating null.Int `db:"rating"`
Organized bool `db:"organized"`
OCounter int `db:"o_counter"`
StudioID null.Int `db:"studio_id,omitempty"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
ID int `db:"id" goqu:"skipinsert"`
Title zero.String `db:"title"`
Rating null.Int `db:"rating"`
Organized bool `db:"organized"`
OCounter int `db:"o_counter"`
StudioID null.Int `db:"studio_id,omitempty"`
CreatedAt models.SQLiteTimestamp `db:"created_at"`
UpdatedAt models.SQLiteTimestamp `db:"updated_at"`
}
func (r *imageRow) fromImage(i models.Image) {
@@ -45,8 +44,8 @@ func (r *imageRow) fromImage(i models.Image) {
r.Organized = i.Organized
r.OCounter = i.OCounter
r.StudioID = intFromPtr(i.StudioID)
r.CreatedAt = i.CreatedAt
r.UpdatedAt = i.UpdatedAt
r.CreatedAt = models.SQLiteTimestamp{Timestamp: i.CreatedAt}
r.UpdatedAt = models.SQLiteTimestamp{Timestamp: i.UpdatedAt}
}
type imageQueryRow struct {
@@ -69,8 +68,8 @@ func (r *imageQueryRow) resolve() *models.Image {
PrimaryFileID: nullIntFileIDPtr(r.PrimaryFileID),
Checksum: r.PrimaryFileChecksum.String,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
CreatedAt: r.CreatedAt.Timestamp,
UpdatedAt: r.UpdatedAt.Timestamp,
}
if r.PrimaryFileFolderPath.Valid && r.PrimaryFileBasename.Valid {