mirror of
https://github.com/navidrome/navidrome.git
synced 2026-06-19 07:37:15 +00:00
32ac53dc9f
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>
35 lines
662 B
Go
35 lines
662 B
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/pressly/goose/v3"
|
|
)
|
|
|
|
func init() {
|
|
goose.AddMigrationContext(Up20201010162350, Down20201010162350)
|
|
}
|
|
|
|
func Up20201010162350(ctx context.Context, tx *sql.Tx) error {
|
|
_, err := tx.ExecContext(ctx, `
|
|
alter table album
|
|
add size integer default 0 not null;
|
|
create index if not exists album_size
|
|
on album(size);
|
|
|
|
update album set size = ifnull((
|
|
select sum(f.size)
|
|
from media_file f
|
|
where f.album_id = album.id
|
|
), 0)
|
|
where id not null;`)
|
|
|
|
return err
|
|
}
|
|
|
|
func Down20201010162350(ctx context.Context, tx *sql.Tx) error {
|
|
// This code is executed when the migration is rolled back.
|
|
return nil
|
|
}
|