mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Add updated_at field to stash_id's (#5259)
* Add updated_at field to stash_id's * Only set updated at on stash ids when actually updating in identify --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -34,7 +34,7 @@ const (
|
||||
cacheSizeEnv = "STASH_SQLITE_CACHE_SIZE"
|
||||
)
|
||||
|
||||
var appSchemaVersion uint = 68
|
||||
var appSchemaVersion uint = 69
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var migrationsBox embed.FS
|
||||
|
||||
3
pkg/sqlite/migrations/69_stash_id_updated_at.up.sql
Normal file
3
pkg/sqlite/migrations/69_stash_id_updated_at.up.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE `performer_stash_ids` ADD COLUMN `updated_at` datetime not null default '1970-01-01T00:00:00Z';
|
||||
ALTER TABLE `scene_stash_ids` ADD COLUMN `updated_at` datetime not null default '1970-01-01T00:00:00Z';
|
||||
ALTER TABLE `studio_stash_ids` ADD COLUMN `updated_at` datetime not null default '1970-01-01T00:00:00Z';
|
||||
@@ -14,11 +14,6 @@ import (
|
||||
|
||||
const idColumn = "id"
|
||||
|
||||
type objectList interface {
|
||||
Append(o interface{})
|
||||
New() interface{}
|
||||
}
|
||||
|
||||
type repository struct {
|
||||
tableName string
|
||||
idColumn string
|
||||
@@ -124,17 +119,6 @@ func (r *repository) queryFunc(ctx context.Context, query string, args []interfa
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repository) query(ctx context.Context, query string, args []interface{}, out objectList) error {
|
||||
return r.queryFunc(ctx, query, args, false, func(rows *sqlx.Rows) error {
|
||||
object := out.New()
|
||||
if err := rows.StructScan(object); err != nil {
|
||||
return err
|
||||
}
|
||||
out.Append(object)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (r *repository) queryStruct(ctx context.Context, query string, args []interface{}, out interface{}) error {
|
||||
if err := r.queryFunc(ctx, query, args, true, func(rows *sqlx.Rows) error {
|
||||
if err := rows.StructScan(out); err != nil {
|
||||
@@ -421,7 +405,7 @@ type stashIDRepository struct {
|
||||
type stashIDs []models.StashID
|
||||
|
||||
func (s *stashIDs) Append(o interface{}) {
|
||||
*s = append(*s, *o.(*models.StashID))
|
||||
*s = append(*s, o.(models.StashID))
|
||||
}
|
||||
|
||||
func (s *stashIDs) New() interface{} {
|
||||
@@ -429,10 +413,17 @@ func (s *stashIDs) New() interface{} {
|
||||
}
|
||||
|
||||
func (r *stashIDRepository) get(ctx context.Context, id int) ([]models.StashID, error) {
|
||||
query := fmt.Sprintf("SELECT stash_id, endpoint from %s WHERE %s = ?", r.tableName, r.idColumn)
|
||||
query := fmt.Sprintf("SELECT stash_id, endpoint, updated_at from %s WHERE %s = ?", r.tableName, r.idColumn)
|
||||
var ret stashIDs
|
||||
err := r.query(ctx, query, []interface{}{id}, &ret)
|
||||
return []models.StashID(ret), err
|
||||
err := r.queryFunc(ctx, query, []interface{}{id}, false, func(rows *sqlx.Rows) error {
|
||||
var v stashIDRow
|
||||
if err := rows.StructScan(&v); err != nil {
|
||||
return err
|
||||
}
|
||||
ret.Append(v.resolve())
|
||||
return nil
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
|
||||
type filesRepository struct {
|
||||
|
||||
@@ -275,19 +275,21 @@ type stashIDTable struct {
|
||||
}
|
||||
|
||||
type stashIDRow struct {
|
||||
StashID null.String `db:"stash_id"`
|
||||
Endpoint null.String `db:"endpoint"`
|
||||
StashID null.String `db:"stash_id"`
|
||||
Endpoint null.String `db:"endpoint"`
|
||||
UpdatedAt Timestamp `db:"updated_at"`
|
||||
}
|
||||
|
||||
func (r *stashIDRow) resolve() models.StashID {
|
||||
return models.StashID{
|
||||
StashID: r.StashID.String,
|
||||
Endpoint: r.Endpoint.String,
|
||||
StashID: r.StashID.String,
|
||||
Endpoint: r.Endpoint.String,
|
||||
UpdatedAt: r.UpdatedAt.Timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *stashIDTable) get(ctx context.Context, id int) ([]models.StashID, error) {
|
||||
q := dialect.Select("endpoint", "stash_id").From(t.table.table).Where(t.idColumn.Eq(id))
|
||||
q := dialect.Select("endpoint", "stash_id", "updated_at").From(t.table.table).Where(t.idColumn.Eq(id))
|
||||
|
||||
const single = false
|
||||
var ret []models.StashID
|
||||
@@ -308,8 +310,8 @@ func (t *stashIDTable) get(ctx context.Context, id int) ([]models.StashID, error
|
||||
}
|
||||
|
||||
func (t *stashIDTable) insertJoin(ctx context.Context, id int, v models.StashID) (sql.Result, error) {
|
||||
q := dialect.Insert(t.table.table).Cols(t.idColumn.GetCol(), "endpoint", "stash_id").Vals(
|
||||
goqu.Vals{id, v.Endpoint, v.StashID},
|
||||
var q = dialect.Insert(t.table.table).Cols(t.idColumn.GetCol(), "endpoint", "stash_id", "updated_at").Vals(
|
||||
goqu.Vals{id, v.Endpoint, v.StashID, v.UpdatedAt},
|
||||
)
|
||||
ret, err := exec(ctx, q)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user