@@ -666,7 +666,11 @@ class Database {
666666 async cleanDatabase ( ) {
667667 // Remove invalid Podcast records
668668 const podcastsWithNoLibraryItem = await this . podcastModel . findAll ( {
669- where : Sequelize . where ( Sequelize . literal ( `(SELECT count(*) FROM libraryItems li WHERE li.mediaId = podcast.id)` ) , 0 )
669+ include : {
670+ model : this . libraryItemModel ,
671+ required : false
672+ } ,
673+ where : { '$libraryItem.id$' : null }
670674 } )
671675 for ( const podcast of podcastsWithNoLibraryItem ) {
672676 Logger . warn ( `Found podcast "${ podcast . title } " with no libraryItem - removing it` )
@@ -675,7 +679,11 @@ class Database {
675679
676680 // Remove invalid Book records
677681 const booksWithNoLibraryItem = await this . bookModel . findAll ( {
678- where : Sequelize . where ( Sequelize . literal ( `(SELECT count(*) FROM libraryItems li WHERE li.mediaId = book.id)` ) , 0 )
682+ include : {
683+ model : this . libraryItemModel ,
684+ required : false
685+ } ,
686+ where : { '$libraryItem.id$' : null }
679687 } )
680688 for ( const book of booksWithNoLibraryItem ) {
681689 Logger . warn ( `Found book "${ book . title } " with no libraryItem - removing it` )
@@ -684,7 +692,11 @@ class Database {
684692
685693 // Remove empty series
686694 const emptySeries = await this . seriesModel . findAll ( {
687- where : Sequelize . where ( Sequelize . literal ( `(SELECT count(*) FROM bookSeries bs WHERE bs.seriesId = series.id)` ) , 0 )
695+ include : {
696+ model : this . bookSeriesModel ,
697+ required : false
698+ } ,
699+ where : { '$bookSeries.id$' : null }
688700 } )
689701 for ( const series of emptySeries ) {
690702 Logger . warn ( `Found series "${ series . name } " with no books - removing it` )
0 commit comments