From ef53a353627b9407a66b3efa76d33c9cc9950086 Mon Sep 17 00:00:00 2001 From: DecDuck Date: Fri, 1 Aug 2025 13:55:01 +1000 Subject: [PATCH 1/3] fix: casade delete for games and library sources --- .../20250801035031_add_delete_casacde/migration.sql | 11 +++++++++++ prisma/models/content.prisma | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20250801035031_add_delete_casacde/migration.sql diff --git a/prisma/migrations/20250801035031_add_delete_casacde/migration.sql b/prisma/migrations/20250801035031_add_delete_casacde/migration.sql new file mode 100644 index 00000000..645377ad --- /dev/null +++ b/prisma/migrations/20250801035031_add_delete_casacde/migration.sql @@ -0,0 +1,11 @@ +-- DropForeignKey +ALTER TABLE "Game" DROP CONSTRAINT "Game_libraryId_fkey"; + +-- DropIndex +DROP INDEX "GameTag_name_idx"; + +-- CreateIndex +CREATE INDEX "GameTag_name_idx" ON "GameTag" USING GIST ("name" gist_trgm_ops(siglen=32)); + +-- AddForeignKey +ALTER TABLE "Game" ADD CONSTRAINT "Game_libraryId_fkey" FOREIGN KEY ("libraryId") REFERENCES "Library"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/models/content.prisma b/prisma/models/content.prisma index 587f2a60..3ab28be6 100644 --- a/prisma/models/content.prisma +++ b/prisma/models/content.prisma @@ -36,7 +36,7 @@ model Game { // These fields will not be optional in the next version // Any game without a library ID will be assigned one at startup, based on the defaults libraryId String? - library Library? @relation(fields: [libraryId], references: [id]) + library Library? @relation(fields: [libraryId], references: [id], onDelete: Cascade, onUpdate: Cascade) libraryPath String collections CollectionEntry[] From c22690dc99f91221b0b9284fc37a38e8f3027f8d Mon Sep 17 00:00:00 2001 From: DecDuck Date: Fri, 1 Aug 2025 13:56:46 +1000 Subject: [PATCH 2/3] fix: add bug workaround --- server/plugins/05.library-init.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/plugins/05.library-init.ts b/server/plugins/05.library-init.ts index bba60901..ac51535c 100644 --- a/server/plugins/05.library-init.ts +++ b/server/plugins/05.library-init.ts @@ -61,6 +61,14 @@ export default defineNitroPlugin(async () => { }); } + // Delete all games that don't have a library provider after the legacy handler + // (leftover from a bug) + await prisma.game.deleteMany({ + where: { + libraryId: null, + } + }); + for (const library of libraries) { const constructor = libraryConstructors[library.backend]; try { From f1fa795b0a9a8591b6194c90f2f5cdfbc0bde064 Mon Sep 17 00:00:00 2001 From: DecDuck Date: Fri, 1 Aug 2025 13:57:09 +1000 Subject: [PATCH 3/3] fix: lint --- server/plugins/05.library-init.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/plugins/05.library-init.ts b/server/plugins/05.library-init.ts index ac51535c..9891b51e 100644 --- a/server/plugins/05.library-init.ts +++ b/server/plugins/05.library-init.ts @@ -66,7 +66,7 @@ export default defineNitroPlugin(async () => { await prisma.game.deleteMany({ where: { libraryId: null, - } + }, }); for (const library of libraries) {