navidrome/db/migrations/20260310113858_fix_aac_transcode_command.go
Deluan 32ac53dc9f refactor(migrations): propagate context.Context through all DB calls
Thread the context.Context that goose.UpContext already passes into every
migration through to all DB calls: tx.Exec/Query/QueryRow become
tx.ExecContext/QueryContext/QueryRowContext with ctx. The shared helpers in
migration.go (notice, forceFullRescan, isDBInitialized) gain a ctx parameter
and all call sites are updated. No-op migration functions use blank params
(_ context.Context, _ *sql.Tx).

This is a behavior-preserving change: the SQL, arguments, and ordering of every
migration are unchanged; only cancellation/deadline propagation is added.

Add a forbidigo lint rule scoped to db/migrations/ that forbids the
non-context tx.Exec/Query/QueryRow forms, preventing regression.

Signed-off-by: Deluan <deluan@navidrome.org>
2026-06-18 09:58:43 -04:00

31 lines
1015 B
Go

package migrations
import (
"context"
"database/sql"
"github.com/pressly/goose/v3"
)
func init() {
goose.AddMigrationContext(upFixAacTranscodeCommand, downFixAacTranscodeCommand)
}
func upFixAacTranscodeCommand(ctx context.Context, tx *sql.Tx) error {
// The old AAC command used `-f ipod -movflags frag_keyframe+empty_moov` which produces
// corrupt/silent audio when ffmpeg pipes to stdout (confirmed in ffmpeg 8.0+).
// Switch to `-f adts` (raw AAC framing) which works reliably via pipe.
// Only update rows that still have the old default command.
const oldCommand = "ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -c:a aac -f ipod -movflags frag_keyframe+empty_moov -"
const newCommand = "ffmpeg -i %s -ss %t -map 0:a:0 -b:a %bk -v 0 -c:a aac -f adts -"
_, err := tx.ExecContext(ctx,
"UPDATE transcoding SET command = ? WHERE target_format = 'aac' AND command = ?",
newCommand, oldCommand,
)
return err
}
func downFixAacTranscodeCommand(_ context.Context, _ *sql.Tx) error {
return nil
}