fix vcenter update task to avoid re-adding update records for previous updates
Some checks are pending
CI / Publish Docker (push) Blocked by required conditions
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-14 12:02:31 +11:00
parent cc6601146a
commit 1ecdb10cf7
4 changed files with 126 additions and 21 deletions

View File

@@ -628,6 +628,54 @@ func (q *Queries) GetReportUpdates(ctx context.Context) ([]Updates, error) {
return items, nil
}
const getVmUpdates = `-- name: GetVmUpdates :many
SELECT Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString FROM "Updates"
WHERE "UpdateType" = ?1 AND "InventoryId" = ?2
`
type GetVmUpdatesParams struct {
UpdateType string
InventoryId sql.NullInt64
}
func (q *Queries) GetVmUpdates(ctx context.Context, arg GetVmUpdatesParams) ([]Updates, error) {
rows, err := q.db.QueryContext(ctx, getVmUpdates, arg.UpdateType, arg.InventoryId)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Updates
for rows.Next() {
var i Updates
if err := rows.Scan(
&i.Uid,
&i.InventoryId,
&i.UpdateTime,
&i.UpdateType,
&i.NewVcpus,
&i.NewRam,
&i.NewResourcePool,
&i.EventKey,
&i.EventId,
&i.NewProvisionedDisk,
&i.UserName,
&i.PlaceholderChange,
&i.Name,
&i.RawChangeString,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const inventoryCleanup = `-- name: InventoryCleanup :exec
DELETE FROM "Inventory"
WHERE "VmId" = ?1 AND "Datacenter" = ?2