diff --git a/internal/report/snapshots.go b/internal/report/snapshots.go index c0a7b21..d216377 100644 --- a/internal/report/snapshots.go +++ b/internal/report/snapshots.go @@ -586,8 +586,17 @@ func CreateTableReport(logger *slog.Logger, Database db.Database, ctx context.Co query = fmt.Sprintf(`%s WHERE %s`, query, templateExclusionFilter()) } orderBy := snapshotOrderBy(columns) + orderDir := "DESC" + isHourly := strings.HasPrefix(tableName, "inventory_hourly_") + isDailySummaryTable := strings.HasPrefix(tableName, "inventory_daily_summary_") + isMonthlySummaryTable := strings.HasPrefix(tableName, "inventory_monthly_summary_") + if hasColumn(columns, "CreationTime") && (isHourly || isDailySummaryTable || isMonthlySummaryTable) { + // Sort inventory rows by creation time ascending so newest VMs appear last. + orderBy = "CreationTime" + orderDir = "ASC" + } if orderBy != "" { - query = fmt.Sprintf(`%s ORDER BY "%s" DESC`, query, orderBy) + query = fmt.Sprintf(`%s ORDER BY "%s" %s`, query, orderBy, orderDir) } rows, err := dbConn.QueryxContext(ctx, query) diff --git a/server/handler/updateCleanup.go b/server/handler/updateCleanup.go index ae9343f..02f48cd 100644 --- a/server/handler/updateCleanup.go +++ b/server/handler/updateCleanup.go @@ -7,9 +7,10 @@ import ( ) // UpdateCleanup removes orphaned update records. -// @Summary Cleanup updates -// @Description Removes update records that are no longer associated with a VM. +// @Summary Cleanup updates (deprecated) +// @Description Deprecated: Removes update records that are no longer associated with a VM. // @Tags maintenance +// @Deprecated // @Produce text/plain // @Success 200 {string} string "Cleanup completed" // @Failure 500 {string} string "Server error" diff --git a/server/handler/vcCleanup.go b/server/handler/vcCleanup.go index 309dac2..867d94b 100644 --- a/server/handler/vcCleanup.go +++ b/server/handler/vcCleanup.go @@ -10,9 +10,10 @@ import ( ) // VcCleanup removes inventory entries for a vCenter instance. -// @Summary Cleanup vCenter inventory -// @Description Removes all inventory entries associated with a vCenter URL. +// @Summary Cleanup vCenter inventory (deprecated) +// @Description Deprecated: Removes all inventory entries associated with a vCenter URL. // @Tags maintenance +// @Deprecated // @Produce json // @Param vc_url query string true "vCenter URL" // @Success 200 {object} map[string]string "Cleanup completed" diff --git a/server/handler/vmCreateEvent.go b/server/handler/vmCreateEvent.go index 756a3e6..a8c85a7 100644 --- a/server/handler/vmCreateEvent.go +++ b/server/handler/vmCreateEvent.go @@ -15,9 +15,10 @@ import ( ) // VmCreateEvent records a VM creation CloudEvent. -// @Summary Record VM create event -// @Description Parses a VM create CloudEvent and stores the event data. +// @Summary Record VM create event (deprecated) +// @Description Deprecated: Parses a VM create CloudEvent and stores the event data. // @Tags events +// @Deprecated // @Accept json // @Produce text/plain // @Param event body models.CloudEventReceived true "CloudEvent payload" diff --git a/server/handler/vmDeleteEvent.go b/server/handler/vmDeleteEvent.go index e754582..234f93c 100644 --- a/server/handler/vmDeleteEvent.go +++ b/server/handler/vmDeleteEvent.go @@ -13,9 +13,10 @@ import ( ) // VmDeleteEvent records a VM deletion CloudEvent in the inventory. -// @Summary Record VM delete event -// @Description Parses a VM delete CloudEvent and marks the VM as deleted in inventory. +// @Summary Record VM delete event (deprecated) +// @Description Deprecated: Parses a VM delete CloudEvent and marks the VM as deleted in inventory. // @Tags events +// @Deprecated // @Accept json // @Produce text/plain // @Param event body models.CloudEventReceived true "CloudEvent payload" diff --git a/server/handler/vmModifyEvent.go b/server/handler/vmModifyEvent.go index 01ebec6..4802d69 100644 --- a/server/handler/vmModifyEvent.go +++ b/server/handler/vmModifyEvent.go @@ -20,9 +20,10 @@ import ( ) // VmModifyEvent records a VM modification CloudEvent. -// @Summary Record VM modify event -// @Description Parses a VM modify CloudEvent and creates an update record when relevant changes are detected. +// @Summary Record VM modify event (deprecated) +// @Description Deprecated: Parses a VM modify CloudEvent and creates an update record when relevant changes are detected. // @Tags events +// @Deprecated // @Accept json // @Produce json // @Param event body models.CloudEventReceived true "CloudEvent payload" diff --git a/server/handler/vmMoveEvent.go b/server/handler/vmMoveEvent.go index f5e2c34..be3dc63 100644 --- a/server/handler/vmMoveEvent.go +++ b/server/handler/vmMoveEvent.go @@ -15,9 +15,10 @@ import ( ) // VmMoveEvent records a VM move CloudEvent as an update. -// @Summary Record VM move event -// @Description Parses a VM move CloudEvent and creates an update record. +// @Summary Record VM move event (deprecated) +// @Description Deprecated: Parses a VM move CloudEvent and creates an update record. // @Tags events +// @Deprecated // @Accept json // @Produce json // @Param event body models.CloudEventReceived true "CloudEvent payload"