From 95864705dcb84d33ec52216f56cf5a7c816d4f47 Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 28 Jan 2025 16:58:42 -0600 Subject: [PATCH] Update clean database to remove invalid CollectionBook records --- server/Database.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/Database.js b/server/Database.js index c9e2d52a..04d024df 100644 --- a/server/Database.js +++ b/server/Database.js @@ -700,6 +700,7 @@ class Database { await libraryItem.destroy() } + // Remove invalid PlaylistMediaItem records const playlistMediaItemsWithNoMediaItem = await this.playlistMediaItemModel.findAll({ include: [ { @@ -721,6 +722,19 @@ class Database { await playlistMediaItem.destroy() } + // Remove invalid CollectionBook records + const collectionBooksWithNoBook = await this.collectionBookModel.findAll({ + include: { + model: this.bookModel, + required: false + }, + where: { '$book.id$': null } + }) + for (const collectionBook of collectionBooksWithNoBook) { + Logger.warn(`Found collectionBook with no book - removing it`) + await collectionBook.destroy() + } + // Remove empty series const emptySeries = await this.seriesModel.findAll({ include: {