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) { 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, }, }) }