refactor: inject data fix dependencies
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
func init() {
|
||||
Register(Fix{
|
||||
ID: "20260526_episode_availability_backfill_next_refresh_at",
|
||||
Apply: func(ctx context.Context, sqlDB *sql.DB) error {
|
||||
Apply: func(ctx context.Context, sqlDB *sql.DB, _ Dependencies) 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, `
|
||||
|
||||
@@ -4,14 +4,17 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"mal/internal"
|
||||
errlog "mal/pkg"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Register(Fix{
|
||||
ID: "20260528_backfill_avatar_url",
|
||||
Apply: func(ctx context.Context, sqlDB *sql.DB) error {
|
||||
Apply: func(ctx context.Context, sqlDB *sql.DB, deps Dependencies) error {
|
||||
if deps.DefaultAvatarURL == nil {
|
||||
return fmt.Errorf("default avatar URL dependency is required")
|
||||
}
|
||||
|
||||
rows, err := sqlDB.QueryContext(ctx, `SELECT id, username FROM user WHERE avatar_url = ''`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("query users missing avatar_url: %w", err)
|
||||
@@ -35,7 +38,7 @@ func init() {
|
||||
}
|
||||
|
||||
for _, u := range toUpdate {
|
||||
avatarURL := internal.DefaultAvatarURL(u.username)
|
||||
avatarURL := deps.DefaultAvatarURL(u.username)
|
||||
if _, err := sqlDB.ExecContext(ctx, `UPDATE user SET avatar_url = ? WHERE id = ?`, avatarURL, u.id); err != nil {
|
||||
return fmt.Errorf("update avatar_url for user %s: %w", u.id, err)
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ type animeDurationRow struct {
|
||||
|
||||
func init() {
|
||||
Register(Fix{
|
||||
ID: "20260608_backfill_anime_duration_seconds",
|
||||
Apply: applyAnimeDurationSecondsBackfill,
|
||||
ID: "20260608_backfill_anime_duration_seconds",
|
||||
Apply: func(ctx context.Context, sqlDB *sql.DB, _ Dependencies) error {
|
||||
return applyAnimeDurationSecondsBackfill(ctx, sqlDB)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ import (
|
||||
|
||||
type Fix struct {
|
||||
ID string
|
||||
Apply func(ctx context.Context, sqlDB *sql.DB) error
|
||||
Apply func(ctx context.Context, sqlDB *sql.DB, deps Dependencies) error
|
||||
}
|
||||
|
||||
type Dependencies struct {
|
||||
DefaultAvatarURL func(username string) string
|
||||
}
|
||||
|
||||
var registered []Fix
|
||||
|
||||
Reference in New Issue
Block a user