refactor: extract data fixes into dedicated package

This commit is contained in:
2026-05-26 15:19:40 +02:00
parent ab5476d3d2
commit 46cff45d0e
4 changed files with 44 additions and 29 deletions

View File

@@ -0,0 +1,28 @@
package fixes
import (
"context"
"database/sql"
"fmt"
)
func init() {
Register(Fix{
ID: "20260526_episode_availability_backfill_next_refresh_at",
Apply: func(ctx context.Context, sqlDB *sql.DB) error {
// Old caches could have next_refresh_at NULL (especially for airing shows with missing broadcast metadata),
// which can result in "never refresh again" behavior on the server.
_, err := sqlDB.ExecContext(ctx, `
UPDATE episode_availability_cache
SET next_refresh_at = datetime(CURRENT_TIMESTAMP, '+6 hours'),
updated_at = CURRENT_TIMESTAMP
WHERE next_refresh_at IS NULL;
`)
if err != nil {
return fmt.Errorf("backfill episode_availability_cache.next_refresh_at: %w", err)
}
return nil
},
})
}

View File

@@ -0,0 +1,25 @@
package fixes
import (
"context"
"database/sql"
"sort"
)
type Fix struct {
ID string
Apply func(ctx context.Context, sqlDB *sql.DB) error
}
var registered []Fix
func Register(fix Fix) {
registered = append(registered, fix)
}
func All() []Fix {
out := append([]Fix(nil), registered...)
sort.Slice(out, func(i, j int) bool { return out[i].ID < out[j].ID })
return out
}