scanner: ormise clean artists
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
//nolint:lll
|
//nolint:lll
|
||||||
package db
|
package db
|
||||||
|
|
||||||
|
// see this db fiddle to mess around with the schema
|
||||||
|
// https://www.db-fiddle.com/f/wJ7z8L7mu6ZKaYmWk1xr1p/5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|||||||
@@ -132,11 +132,14 @@ func (s *Scanner) cleanFolders() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) cleanArtists() (int, error) {
|
func (s *Scanner) cleanArtists() (int, error) {
|
||||||
q := s.db.Exec(`
|
sub := s.db.
|
||||||
DELETE FROM artists
|
Select("1").
|
||||||
WHERE NOT EXISTS ( SELECT 1 FROM albums
|
Model(&db.Album{}).
|
||||||
WHERE albums.tag_artist_id=artists.id )
|
Where("albums.tag_artist_id=artists.id").
|
||||||
`)
|
SubQuery()
|
||||||
|
q := s.db.
|
||||||
|
Where("NOT EXISTS ?", sub).
|
||||||
|
Delete(&db.Artist{})
|
||||||
return int(q.RowsAffected), q.Error
|
return int(q.RowsAffected), q.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user