mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Scene play and o-counter history view and editing (#4532)
Co-authored-by: randemgame <61895715+randemgame@users.noreply.github.com>
This commit is contained in:
71
pkg/sqlite/migrations/55_postmigrate.go
Normal file
71
pkg/sqlite/migrations/55_postmigrate.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/sqlite"
|
||||
)
|
||||
|
||||
type schema55Migrator struct {
|
||||
migrator
|
||||
}
|
||||
|
||||
func post55(ctx context.Context, db *sqlx.DB) error {
|
||||
logger.Info("Running post-migration for schema version 55")
|
||||
|
||||
m := schema55Migrator{
|
||||
migrator: migrator{
|
||||
db: db,
|
||||
},
|
||||
}
|
||||
|
||||
return m.migrate(ctx)
|
||||
}
|
||||
|
||||
func (m *schema55Migrator) migrate(ctx context.Context) error {
|
||||
// the last_played_at column was storing in a different format than the rest of the timestamps
|
||||
// convert the play history date to the correct format
|
||||
if err := m.withTxn(ctx, func(tx *sqlx.Tx) error {
|
||||
query := "SELECT DISTINCT `scene_id`, `view_date` FROM `scenes_view_dates`"
|
||||
|
||||
rows, err := m.db.Query(query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var (
|
||||
id int
|
||||
viewDate sqlite.Timestamp
|
||||
)
|
||||
|
||||
err := rows.Scan(&id, &viewDate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utcTimestamp := sqlite.UTCTimestamp{
|
||||
Timestamp: viewDate,
|
||||
}
|
||||
|
||||
// convert the timestamp to the correct format
|
||||
if _, err := m.db.Exec("UPDATE scenes_view_dates SET view_date = ? WHERE view_date = ?", utcTimestamp, viewDate.Timestamp); err != nil {
|
||||
return fmt.Errorf("error correcting view date %s to %s: %w", viewDate.Timestamp, viewDate, err)
|
||||
}
|
||||
}
|
||||
|
||||
return rows.Err()
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
sqlite.RegisterPostMigration(55, post55)
|
||||
}
|
||||
Reference in New Issue
Block a user