mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
refactor(db): apply review feedback to id migration
Filter empty strings in collectColumn's SQL, reuse a prepared statement for rewriteColumn updates, and clarify the legacy ID functions' comment now that they emit the canonical encoding.
This commit is contained in:
parent
0623694c0a
commit
3fff973ab6
@ -98,7 +98,7 @@ func buildIDMap(ctx context.Context, tx *sql.Tx) error {
|
||||
|
||||
func collectColumn(ctx context.Context, tx *sql.Tx, ins *sql.Stmt, table, col string) error {
|
||||
rows, err := tx.QueryContext(ctx, fmt.Sprintf(
|
||||
"SELECT DISTINCT %[2]s FROM %[1]s WHERE %[2]s IS NOT NULL", table, col))
|
||||
"SELECT DISTINCT %[2]s FROM %[1]s WHERE %[2]s IS NOT NULL AND %[2]s <> ''", table, col))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -168,9 +168,16 @@ func rewriteColumn(ctx context.Context, tx *sql.Tx, table, col string, transform
|
||||
return err
|
||||
}
|
||||
_ = rows.Close()
|
||||
if len(changes) == 0 {
|
||||
return nil
|
||||
}
|
||||
upd, err := tx.PrepareContext(ctx, fmt.Sprintf("UPDATE %s SET %s = ? WHERE rowid = ?", table, col))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer upd.Close()
|
||||
for _, c := range changes {
|
||||
if _, err := tx.ExecContext(ctx, fmt.Sprintf(
|
||||
"UPDATE %s SET %s = ? WHERE rowid = ?", table, col), c.val, c.rowid); err != nil {
|
||||
if _, err := upd.ExecContext(ctx, c.val, c.rowid); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,8 +12,8 @@ import (
|
||||
"github.com/navidrome/navidrome/model/id"
|
||||
)
|
||||
|
||||
// These are the legacy ID functions that were used in the original Navidrome ID generation.
|
||||
// They are kept here for backwards compatibility with existing databases.
|
||||
// These legacy ID functions hash the same inputs as the original Navidrome ID generation,
|
||||
// now emitted in the canonical base62 encoding (matching what the uniform-ids migration stores).
|
||||
|
||||
func legacyTrackID(mf model.MediaFile, prependLibId bool) string {
|
||||
key := mf.Path
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user