From 4cceda7b61867474dbf1c50c954f9edd334f4ac2 Mon Sep 17 00:00:00 2001 From: LukeGus Date: Fri, 14 Nov 2025 15:22:14 -0600 Subject: [PATCH] fix: Unable to delete hosts --- src/backend/database/routes/ssh.ts | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/backend/database/routes/ssh.ts b/src/backend/database/routes/ssh.ts index e73b6d70..aeb69458 100644 --- a/src/backend/database/routes/ssh.ts +++ b/src/backend/database/routes/ssh.ts @@ -892,6 +892,44 @@ router.delete( const numericHostId = Number(hostId); + // Delete related records first to avoid foreign key constraint errors + await db + .delete(fileManagerRecent) + .where( + and( + eq(fileManagerRecent.hostId, numericHostId), + eq(fileManagerRecent.userId, userId), + ), + ); + + await db + .delete(fileManagerPinned) + .where( + and( + eq(fileManagerPinned.hostId, numericHostId), + eq(fileManagerPinned.userId, userId), + ), + ); + + await db + .delete(fileManagerShortcuts) + .where( + and( + eq(fileManagerShortcuts.hostId, numericHostId), + eq(fileManagerShortcuts.userId, userId), + ), + ); + + await db + .delete(commandHistory) + .where( + and( + eq(commandHistory.hostId, numericHostId), + eq(commandHistory.userId, userId), + ), + ); + + // Now delete the host itself await db .delete(sshData) .where(and(eq(sshData.id, numericHostId), eq(sshData.userId, userId)));