Files
vctp2/server/handler/snapshotMigrate.go
Nathan Coad 9a561f3b07
All checks were successful
continuous-integration/drone/push Build is passing
cleanups and code fixes incl templ
2026-03-20 13:21:15 +11:00

52 lines
1.6 KiB
Go

package handler
import (
"net/http"
"vctp/internal/report"
"vctp/server/models"
)
// SnapshotMigrate rebuilds the snapshot registry and normalizes hourly table names.
// @Summary Migrate snapshot registry
// @Description Rebuilds the snapshot registry from existing tables and renames hourly tables to epoch-based names.
// @Tags snapshots
// @Produce json
// @Success 200 {object} models.SnapshotMigrationResponse "Migration results"
// @Failure 500 {object} models.SnapshotMigrationResponse "Server error"
// @Router /api/snapshots/migrate [post]
func (h *Handler) SnapshotMigrate(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeJSONError(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
ctx, cancel := withRequestTimeout(r, reportRequestTimeout)
defer cancel()
stats, err := report.MigrateSnapshotRegistry(ctx, h.Database)
if err != nil {
writeJSON(w, http.StatusInternalServerError, models.SnapshotMigrationResponse{
Status: "ERROR",
Error: err.Error(),
Stats: models.SnapshotMigrationStats{
HourlyRenamed: stats.HourlyRenamed,
HourlyRegistered: stats.HourlyRegistered,
DailyRegistered: stats.DailyRegistered,
MonthlyRegistered: stats.MonthlyRegistered,
Errors: stats.Errors,
},
})
return
}
writeJSON(w, http.StatusOK, models.SnapshotMigrationResponse{
Status: "OK",
Stats: models.SnapshotMigrationStats{
HourlyRenamed: stats.HourlyRenamed,
HourlyRegistered: stats.HourlyRegistered,
DailyRegistered: stats.DailyRegistered,
MonthlyRegistered: stats.MonthlyRegistered,
Errors: stats.Errors,
},
})
}