mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
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>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/pressly/goose/v3"
|
|
)
|
|
|
|
func init() {
|
|
goose.AddMigrationContext(Up20200423204116, Down20200423204116)
|
|
}
|
|
|
|
func Up20200423204116(ctx context.Context, tx *sql.Tx) error {
|
|
_, err := tx.ExecContext(ctx, `
|
|
alter table artist
|
|
add order_artist_name varchar(255) collate nocase;
|
|
alter table artist
|
|
add sort_artist_name varchar(255) collate nocase;
|
|
create index if not exists artist_order_artist_name
|
|
on artist (order_artist_name);
|
|
|
|
alter table album
|
|
add order_album_name varchar(255) collate nocase;
|
|
alter table album
|
|
add order_album_artist_name varchar(255) collate nocase;
|
|
alter table album
|
|
add sort_album_name varchar(255) collate nocase;
|
|
alter table album
|
|
add sort_artist_name varchar(255) collate nocase;
|
|
alter table album
|
|
add sort_album_artist_name varchar(255) collate nocase;
|
|
create index if not exists album_order_album_name
|
|
on album (order_album_name);
|
|
create index if not exists album_order_album_artist_name
|
|
on album (order_album_artist_name);
|
|
|
|
alter table media_file
|
|
add order_album_name varchar(255) collate nocase;
|
|
alter table media_file
|
|
add order_album_artist_name varchar(255) collate nocase;
|
|
alter table media_file
|
|
add order_artist_name varchar(255) collate nocase;
|
|
alter table media_file
|
|
add sort_album_name varchar(255) collate nocase;
|
|
alter table media_file
|
|
add sort_artist_name varchar(255) collate nocase;
|
|
alter table media_file
|
|
add sort_album_artist_name varchar(255) collate nocase;
|
|
alter table media_file
|
|
add sort_title varchar(255) collate nocase;
|
|
create index if not exists media_file_order_album_name
|
|
on media_file (order_album_name);
|
|
create index if not exists media_file_order_artist_name
|
|
on media_file (order_artist_name);
|
|
`)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
notice(ctx, tx, "A full rescan will be performed to change the search behaviour")
|
|
return forceFullRescan(ctx, tx)
|
|
}
|
|
|
|
func Down20200423204116(_ context.Context, _ *sql.Tx) error {
|
|
return nil
|
|
}
|