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

@@ -31,7 +31,7 @@ func (m *schema55Migrator) 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
}
@@ -53,7 +53,7 @@ func (m *schema55Migrator) migrate(ctx context.Context) error {
}
// 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 {
if _, err := tx.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)
}
}