Skip to content

Commit

Permalink
lxd/db/cluster: Run make update-schema
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
(cherry picked from commit decddf5adfbd0c34c1f189c4eff16c19b3527abd)
  • Loading branch information
hamistao committed Oct 22, 2024
1 parent 3a1bfb0 commit a6a2b2a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lxd/db/cluster/warnings.mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ SELECT warnings.id, coalesce(nodes.name, '') AS node, coalesce(projects.name, ''
ORDER BY warnings.uuid
`)

var warningObjectsByNode = RegisterStmt(`
SELECT warnings.id, coalesce(nodes.name, '') AS node, coalesce(projects.name, '') AS project, coalesce(warnings.entity_type_code, -1), coalesce(warnings.entity_id, -1), warnings.uuid, warnings.type_code, warnings.status, warnings.first_seen_date, warnings.last_seen_date, warnings.updated_date, warnings.last_message, warnings.count
FROM warnings
LEFT JOIN nodes ON warnings.node_id = nodes.id
LEFT JOIN projects ON warnings.project_id = projects.id
WHERE ( coalesce(node, '') = ? )
ORDER BY warnings.uuid
`)

var warningObjectsByNodeAndTypeCode = RegisterStmt(`
SELECT warnings.id, coalesce(nodes.name, '') AS node, coalesce(projects.name, '') AS project, coalesce(warnings.entity_type_code, -1), coalesce(warnings.entity_id, -1), warnings.uuid, warnings.type_code, warnings.status, warnings.first_seen_date, warnings.last_seen_date, warnings.updated_date, warnings.last_message, warnings.count
FROM warnings
Expand Down Expand Up @@ -310,6 +319,30 @@ func GetWarnings(ctx context.Context, tx *sql.Tx, filters ...WarningFilter) ([]W
continue
}

_, where, _ := strings.Cut(parts[0], "WHERE")
queryParts[0] += "OR" + where
} else if filter.Node != nil && filter.ID == nil && filter.UUID == nil && filter.Project == nil && filter.TypeCode == nil && filter.EntityType == nil && filter.EntityID == nil && filter.Status == nil {
args = append(args, []any{filter.Node}...)
if len(filters) == 1 {
sqlStmt, err = Stmt(tx, warningObjectsByNode)
if err != nil {
return nil, fmt.Errorf("Failed to get \"warningObjectsByNode\" prepared statement: %w", err)
}

break
}

query, err := StmtString(warningObjectsByNode)
if err != nil {
return nil, fmt.Errorf("Failed to get \"warningObjects\" prepared statement: %w", err)
}

parts := strings.SplitN(query, "ORDER BY", 2)
if i == 0 {
copy(queryParts[:], parts)
continue
}

_, where, _ := strings.Cut(parts[0], "WHERE")
queryParts[0] += "OR" + where
} else if filter.ID == nil && filter.UUID == nil && filter.Project == nil && filter.Node == nil && filter.TypeCode == nil && filter.EntityType == nil && filter.EntityID == nil && filter.Status == nil {
Expand Down

0 comments on commit a6a2b2a

Please sign in to comment.