fix: correct platform format in version detection

Created version package for semantic version comparison.
Fixed GetLatestVersionByTypeAndArch to use combined platform format.
Replaced inline version comparison with reusable version.Compare().
This commit is contained in:
Fimeg
2025-11-10 21:50:46 -05:00
parent c95cc7d91f
commit ddaa9ac637
3 changed files with 81 additions and 42 deletions

View File

@@ -240,17 +240,20 @@ func (q *AgentUpdateQueries) GetLatestVersion(platform string) (string, error) {
// GetLatestVersionByTypeAndArch retrieves the latest available version for a specific os_type and architecture
func (q *AgentUpdateQueries) GetLatestVersionByTypeAndArch(osType, osArch string) (string, error) {
// Use combined platform format to match agent_update_packages storage
platformStr := osType + "-" + osArch
query := `
SELECT version FROM agent_update_packages
WHERE platform = $1 AND architecture = $2 AND is_active = true
WHERE (platform || '-' || architecture) = $1 AND is_active = true
ORDER BY version DESC LIMIT 1
`
var latestVersion string
err := q.db.Get(&latestVersion, query, osType, osArch)
err := q.db.Get(&latestVersion, query, platformStr)
if err != nil {
if err == sql.ErrNoRows {
return "", fmt.Errorf("no update packages available for platform %s/%s", osType, osArch)
return "", fmt.Errorf("no update packages available for platform %s", platformStr)
}
return "", fmt.Errorf("failed to get latest version: %w", err)
}