fix: repair version detection platform query format
- Fix GetLatestVersionByTypeAndArch to separate platform/architecture - Query now correctly uses platform='linux' and architecture='amd64' - Resolves UI showing 'no packages available' despite updates existing
This commit is contained in:
@@ -216,4 +216,66 @@ func (q *AgentUpdateQueries) GetAgentByMachineID(machineID string) (*models.Agen
|
||||
}
|
||||
|
||||
return &agent, nil
|
||||
}
|
||||
|
||||
// GetLatestVersion retrieves the latest available version for a platform
|
||||
func (q *AgentUpdateQueries) GetLatestVersion(platform string) (string, error) {
|
||||
query := `
|
||||
SELECT version FROM agent_update_packages
|
||||
WHERE platform = $1 AND is_active = true
|
||||
ORDER BY version DESC LIMIT 1
|
||||
`
|
||||
|
||||
var latestVersion string
|
||||
err := q.db.Get(&latestVersion, query, platform)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return "", fmt.Errorf("no update packages available for platform %s", platform)
|
||||
}
|
||||
return "", fmt.Errorf("failed to get latest version: %w", err)
|
||||
}
|
||||
|
||||
return latestVersion, nil
|
||||
}
|
||||
|
||||
// GetLatestVersionByTypeAndArch retrieves the latest available version for a specific os_type and architecture
|
||||
func (q *AgentUpdateQueries) GetLatestVersionByTypeAndArch(osType, osArch string) (string, error) {
|
||||
query := `
|
||||
SELECT version FROM agent_update_packages
|
||||
WHERE platform = $1 AND architecture = $2 AND is_active = true
|
||||
ORDER BY version DESC LIMIT 1
|
||||
`
|
||||
|
||||
var latestVersion string
|
||||
err := q.db.Get(&latestVersion, query, osType, osArch)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return "", fmt.Errorf("no update packages available for platform %s/%s", osType, osArch)
|
||||
}
|
||||
return "", fmt.Errorf("failed to get latest version: %w", err)
|
||||
}
|
||||
|
||||
return latestVersion, nil
|
||||
}
|
||||
|
||||
// GetPendingUpdateCommand retrieves the most recent pending update command for an agent
|
||||
func (q *AgentUpdateQueries) GetPendingUpdateCommand(agentID string) (*models.AgentCommand, error) {
|
||||
query := `
|
||||
SELECT id, agent_id, command_type, params, status, source, created_at, sent_at, completed_at, result, retried_from_id
|
||||
FROM agent_commands
|
||||
WHERE agent_id = $1 AND command_type = 'install_update' AND status = 'pending'
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
var command models.AgentCommand
|
||||
err := q.db.Get(&command, query, agentID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil // No pending update command found
|
||||
}
|
||||
return nil, fmt.Errorf("failed to get pending update command: %w", err)
|
||||
}
|
||||
|
||||
return &command, nil
|
||||
}
|
||||
Reference in New Issue
Block a user