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.
This commit is contained in:
Mathis H (Avnyr) 2024-10-15 14:24:00 +02:00
parent 18a5999334
commit 6f0f209e00
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -103,6 +103,13 @@ export class FilesService {
} }
if (sameFileInStorage.length === 1) { if (sameFileInStorage.length === 1) {
//if there is one only entry then remove the file from the storage and the database. //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 await this.database
.use() .use()
.delete(FilesTable) .delete(FilesTable)