fixed duplicated repo url issue

This commit is contained in:
Muhammad Ibrahim
2025-09-19 15:59:45 +01:00
parent 51d6dd63b1
commit 6bc4316fbc
2 changed files with 28 additions and 8 deletions

1
.gitignore vendored
View File

@@ -143,3 +143,4 @@ manage-patchmon.sh
setup-installer-site.sh setup-installer-site.sh
install-server.* install-server.*
notify-clients-upgrade.sh notify-clients-upgrade.sh
debug-agent.sh

View File

@@ -332,15 +332,34 @@ router.post('/update', validateApiCredentials, [
}); });
} }
// Create host repository relationship // Create host repository relationship (handle duplicates gracefully)
await tx.hostRepository.create({ try {
data: { await tx.hostRepository.create({
hostId: host.id, data: {
repositoryId: repo.id, hostId: host.id,
isEnabled: repoData.isEnabled !== false, // Default to enabled repositoryId: repo.id,
lastChecked: new Date() isEnabled: repoData.isEnabled !== false, // Default to enabled
lastChecked: new Date()
}
});
} catch (error) {
// If it's a duplicate constraint error, update the existing record
if (error.code === 'P2002') {
await tx.hostRepository.updateMany({
where: {
hostId: host.id,
repositoryId: repo.id
},
data: {
isEnabled: repoData.isEnabled !== false,
lastChecked: new Date()
}
});
} else {
// Re-throw other errors
throw error;
} }
}); }
} }
} }
}); });