fix postgres code path
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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{})
|
||||
|
||||
Reference in New Issue
Block a user