Fix double escaped lyrics and comments

This commit is contained in:
Deluan
2021-10-26 19:33:21 -04:00
parent 5e87280750
commit f645c4769c
5 changed files with 62 additions and 13 deletions
@@ -0,0 +1,46 @@
package migrations
import (
"database/sql"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/utils"
"github.com/pressly/goose"
)
func init() {
goose.AddMigration(upUnescapeLyricsAndComments, downUnescapeLyricsAndComments)
}
func upUnescapeLyricsAndComments(tx *sql.Tx) error {
rows, err := tx.Query(`select id, comment, lyrics, title from media_file`)
if err != nil {
return err
}
defer rows.Close()
stmt, err := tx.Prepare("update media_file set comment = ?, lyrics = ? where id = ?")
if err != nil {
return err
}
var id, comment, lyrics, title string
for rows.Next() {
err = rows.Scan(&id, &comment, &lyrics, &title)
if err != nil {
return err
}
comment = utils.SanitizeText(comment)
lyrics = utils.SanitizeText(lyrics)
_, err = stmt.Exec(comment, lyrics, id)
if err != nil {
log.Error("Error unescaping media_file's lyrics and comments", "title", title, "id", id, err)
}
}
return rows.Err()
}
func downUnescapeLyricsAndComments(tx *sql.Tx) error {
return nil
}