From 6f0f209e000c72400196506026fd15421244adea Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 15 Oct 2024 14:24:00 +0200 Subject: [PATCH] Delete associated machine file entries before removing main file Added a step to delete file associations from `FilesForMachinesTable` before deleting the main file from `FilesTable`. This ensures proper cleanup of related entries in the database. --- apps/backend/src/app/files/files.service.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/backend/src/app/files/files.service.ts b/apps/backend/src/app/files/files.service.ts index f567a78..161e9b4 100644 --- a/apps/backend/src/app/files/files.service.ts +++ b/apps/backend/src/app/files/files.service.ts @@ -103,6 +103,13 @@ export class FilesService { } if (sameFileInStorage.length === 1) { //if there is one only entry then remove the file from the storage and the database. + await this.database + .use() + .delete(FilesForMachinesTable) + .where(eq(FilesForMachinesTable.fileId, fileId)) + .prepare("deleteFileAssociationFromMachine") + .execute(); + await this.database .use() .delete(FilesTable)