Files
vctp2/server/handler/snapshotMigrate.go
T
nathan 7848557002
continuous-integration/drone/push Build is passing
update docs
2026-04-17 14:00:48 +10:00

54 lines
1.7 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.
// @Description Requires Bearer authentication with the admin role.
// @Tags snapshots
// @Produce json
// @Success 200 {object} models.SnapshotMigrationResponse "Migration results"
// @Failure 500 {object} models.SnapshotMigrationResponse "Server error"
// @Security BearerAuth
// @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,
},
})
}