39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"vctp/internal/report"
|
|
)
|
|
|
|
// 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) {
|
|
ctx := context.Background()
|
|
stats, err := report.MigrateSnapshotRegistry(ctx, h.Database)
|
|
if err != nil {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"status": "ERROR",
|
|
"error": err.Error(),
|
|
"stats": stats,
|
|
})
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"status": "OK",
|
|
"stats": stats,
|
|
})
|
|
}
|