fix postgres code path
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-11 09:54:55 +11:00
parent a09d94a266
commit ee3b2d7f21
2 changed files with 8 additions and 9 deletions

View File

@@ -12,7 +12,6 @@ import (
"sync"
"time"
"vctp/db"
"vctp/db/queries"
"vctp/internal/metrics"
"vctp/internal/report"
)
@@ -559,7 +558,6 @@ WHERE "Vcenter" = ? AND "DeletedAt" IS NOT NULL AND "DeletedAt" > 0 AND "Deleted
}
func (c *CronTask) applyInventoryDeletions(ctx context.Context, agg map[dailyAggKey]*dailyAggVal, start, end time.Time) int {
dbConn := c.Database.DB()
vcenters := make(map[string]struct{}, 8)
for k := range agg {
if k.Vcenter != "" {
@@ -568,7 +566,7 @@ func (c *CronTask) applyInventoryDeletions(ctx context.Context, agg map[dailyAgg
}
totalApplied := 0
for vcenter := range vcenters {
inventoryRows, err := queries.New(dbConn).GetInventoryByVcenter(ctx, vcenter)
inventoryRows, err := c.Database.Queries().GetInventoryByVcenter(ctx, vcenter)
if err != nil {
c.Logger.Warn("failed to load inventory for daily deletion times", "vcenter", vcenter, "error", err)
continue

View File

@@ -840,8 +840,8 @@ func snapshotFromInventory(inv queries.Inventory, snapshotTime time.Time) Invent
}
}
func loadInventoryMaps(ctx context.Context, dbConn *sqlx.DB, url string) ([]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, error) {
inventoryRows, err := queries.New(dbConn).GetInventoryByVcenter(ctx, url)
func loadInventoryMaps(ctx context.Context, querier db.Querier, url string) ([]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, error) {
inventoryRows, err := querier.GetInventoryByVcenter(ctx, url)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("unable to query inventory table: %w", err)
}
@@ -862,7 +862,7 @@ func loadInventoryMaps(ctx context.Context, dbConn *sqlx.DB, url string) ([]quer
return inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, nil
}
func prepareDeletionCandidates(ctx context.Context, log *slog.Logger, dbConn *sqlx.DB, url string, inventoryRows []queries.Inventory,
func prepareDeletionCandidates(ctx context.Context, log *slog.Logger, dbConn *sqlx.DB, querier db.Querier, url string, inventoryRows []queries.Inventory,
presentSnapshots map[string]InventorySnapshotRow, presentByUuid, presentByName map[string]struct{}, startTime time.Time) (int, bool, []deletionCandidate) {
candidates := make([]deletionCandidate, 0)
missingCount := 0
@@ -904,7 +904,7 @@ func prepareDeletionCandidates(ctx context.Context, log *slog.Logger, dbConn *sq
if !row.DeletionTime.Valid {
deletionTime := startTime.Unix()
row.DeletionTime = sql.NullInt64{Int64: deletionTime, Valid: true}
if err := queries.New(dbConn).InventoryMarkDeleted(ctx, queries.InventoryMarkDeletedParams{
if err := querier.InventoryMarkDeleted(ctx, queries.InventoryMarkDeletedParams{
DeletionTime: row.DeletionTime,
VmId: inv.VmId,
DatacenterName: inv.Datacenter,
@@ -1070,7 +1070,8 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
folderLookup := resources.folderLookup
rpLookup := resources.rpLookup
inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, err := loadInventoryMaps(ctx, c.Database.DB(), url)
q := c.Database.Queries()
inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, err := loadInventoryMaps(ctx, q, url)
if err != nil {
return err
}
@@ -1093,7 +1094,7 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
}
log.Debug("checking inventory for missing VMs")
missingCount, deletionsMarked, candidates := prepareDeletionCandidates(ctx, log, dbConn, url, inventoryRows, presentSnapshots, presentByUuid, presentByName, startTime)
missingCount, deletionsMarked, candidates := prepareDeletionCandidates(ctx, log, dbConn, q, url, inventoryRows, presentSnapshots, presentByUuid, presentByName, startTime)
newCount := 0
prevTableName := ""
reportTables := make(map[string]struct{})