navidrome/db/migrations/20200706231659_add_default_...

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

44 lines
929 B
Go
Raw Normal View History

package migrations
import (
2023-11-27 20:46:44 +01:00
"context"
"database/sql"
"github.com/google/uuid"
"github.com/navidrome/navidrome/consts"
2023-04-04 15:57:00 +02:00
"github.com/pressly/goose/v3"
)
func init() {
2023-11-27 20:46:44 +01:00
goose.AddMigrationContext(upAddDefaultTranscodings, downAddDefaultTranscodings)
}
2023-11-27 20:46:44 +01:00
func upAddDefaultTranscodings(_ context.Context, tx *sql.Tx) error {
row := tx.QueryRow("SELECT COUNT(*) FROM transcoding")
var count int
err := row.Scan(&count)
if err != nil {
return err
}
if count > 0 {
return nil
}
stmt, err := tx.Prepare("insert into transcoding (id, name, target_format, default_bit_rate, command) values (?, ?, ?, ?, ?)")
if err != nil {
return err
}
for _, t := range consts.DefaultTranscodings {
_, err := stmt.Exec(uuid.NewString(), t.Name, t.TargetFormat, t.DefaultBitRate, t.Command)
if err != nil {
return err
}
}
return nil
}
2023-11-27 20:46:44 +01:00
func downAddDefaultTranscodings(_ context.Context, tx *sql.Tx) error {
return nil
}