navidrome/db/migration/20211026191915_unescape_lyr...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.1 KiB
Go
Raw Normal View History

2021-10-27 01:33:21 +02:00
package migrations
import (
2023-11-27 20:46:44 +01:00
"context"
2021-10-27 01:33:21 +02:00
"database/sql"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/utils"
2023-04-04 15:57:00 +02:00
"github.com/pressly/goose/v3"
2021-10-27 01:33:21 +02:00
)
func init() {
2023-11-27 20:46:44 +01:00
goose.AddMigrationContext(upUnescapeLyricsAndComments, downUnescapeLyricsAndComments)
2021-10-27 01:33:21 +02:00
}
2023-11-27 20:46:44 +01:00
func upUnescapeLyricsAndComments(_ context.Context, tx *sql.Tx) error {
2021-10-27 01:33:21 +02:00
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
}
2021-11-05 02:23:41 +01:00
var id, title string
var comment, lyrics sql.NullString
2021-10-27 01:33:21 +02:00
for rows.Next() {
err = rows.Scan(&id, &comment, &lyrics, &title)
if err != nil {
return err
}
2021-11-05 02:23:41 +01:00
newComment := utils.SanitizeText(comment.String)
newLyrics := utils.SanitizeText(lyrics.String)
_, err = stmt.Exec(newComment, newLyrics, id)
2021-10-27 01:33:21 +02:00
if err != nil {
log.Error("Error unescaping media_file's lyrics and comments", "title", title, "id", id, err)
}
}
return rows.Err()
}
2023-11-27 20:46:44 +01:00
func downUnescapeLyricsAndComments(_ context.Context, tx *sql.Tx) error {
2021-10-27 01:33:21 +02:00
return nil
}