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>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/pressly/goose/v3"
|
|
)
|
|
|
|
func init() {
|
|
goose.AddMigrationContext(upCreateBookmarkTable, downCreateBookmarkTable)
|
|
}
|
|
|
|
func upCreateBookmarkTable(ctx context.Context, tx *sql.Tx) error {
|
|
_, err := tx.ExecContext(ctx, `
|
|
create table bookmark
|
|
(
|
|
user_id varchar(255) not null
|
|
references user
|
|
on update cascade on delete cascade,
|
|
item_id varchar(255) not null,
|
|
item_type varchar(255) not null,
|
|
comment varchar(255),
|
|
position integer,
|
|
changed_by varchar(255),
|
|
created_at datetime,
|
|
updated_at datetime,
|
|
constraint bookmark_pk
|
|
unique (user_id, item_id, item_type)
|
|
);
|
|
|
|
create table playqueue_dg_tmp
|
|
(
|
|
id varchar(255) not null,
|
|
user_id varchar(255) not null
|
|
references user
|
|
on update cascade on delete cascade,
|
|
current varchar(255),
|
|
position real,
|
|
changed_by varchar(255),
|
|
items varchar(255),
|
|
created_at datetime,
|
|
updated_at datetime
|
|
);
|
|
drop table playqueue;
|
|
alter table playqueue_dg_tmp rename to playqueue;
|
|
`)
|
|
|
|
return err
|
|
}
|
|
|
|
func downCreateBookmarkTable(_ context.Context, _ *sql.Tx) error {
|
|
return nil
|
|
}
|