Fix migrations not using tx (#5282)

This commit is contained in:
WithoutPants
2024-09-22 14:03:54 +10:00
committed by GitHub
parent fd9e4b3ec2
commit 7e8c764dc7
9 changed files with 50 additions and 48 deletions

View File

@@ -35,7 +35,7 @@ func (m *schema64Migrator) migrate(ctx context.Context) error {
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)
rows, err := tx.Query(query)
if err != nil {
return err
}
@@ -64,7 +64,7 @@ func (m *schema64Migrator) migrate(ctx context.Context) error {
// convert the timestamp to the correct format
logger.Debugf("correcting view date %q to UTC date %q for scene %d", viewDate.Timestamp, viewDate.Timestamp.UTC(), id)
r, err := m.db.Exec("UPDATE scenes_view_dates SET view_date = ? WHERE scene_id = ? AND (view_date = ? OR view_date = ?)", utcTimestamp, id, viewDate.Timestamp, viewDate)
r, err := tx.Exec("UPDATE scenes_view_dates SET view_date = ? WHERE scene_id = ? AND (view_date = ? OR view_date = ?)", utcTimestamp, id, viewDate.Timestamp, viewDate)
if err != nil {
return fmt.Errorf("error correcting view date %s to %s: %w", viewDate.Timestamp, viewDate, err)
}