Remove non-album artist_ids from the DB

This commit is contained in:
Deluan
2021-11-05 20:24:41 -04:00
parent 0d9dcebf32
commit 1c82bf5179
5 changed files with 53 additions and 1 deletions
@@ -0,0 +1,22 @@
package migrations
import (
"database/sql"
"github.com/pressly/goose"
)
func init() {
goose.AddMigration(upRemoveInvalidArtistIds, downRemoveInvalidArtistIds)
}
func upRemoveInvalidArtistIds(tx *sql.Tx) error {
_, err := tx.Exec(`
update media_file set artist_id = '' where not exists(select 1 from artist where id = artist_id)
`)
return err
}
func downRemoveInvalidArtistIds(tx *sql.Tx) error {
return nil
}