mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 11:12:58 +08:00
Query history: Add migration endpoint (#47551)
* Add endpoint for migration * Check for createdAt * Query history: Remove returning of dtos * Query history: Fix CreatedAt * Refactor based on suggestions * Insert into table in batches
This commit is contained in:
@ -19,6 +19,8 @@ func (s *QueryHistoryService) registerAPIEndpoints() {
|
||||
entities.Post("/star/:uid", middleware.ReqSignedIn, routing.Wrap(s.starHandler))
|
||||
entities.Delete("/star/:uid", middleware.ReqSignedIn, routing.Wrap(s.unstarHandler))
|
||||
entities.Patch("/:uid", middleware.ReqSignedIn, routing.Wrap(s.patchCommentHandler))
|
||||
// Remove migrate endpoint in Grafana v10 as breaking change
|
||||
entities.Post("/migrate", middleware.ReqSignedIn, routing.Wrap(s.migrateHandler))
|
||||
})
|
||||
}
|
||||
|
||||
@ -117,3 +119,17 @@ func (s *QueryHistoryService) unstarHandler(c *models.ReqContext) response.Respo
|
||||
|
||||
return response.JSON(http.StatusOK, QueryHistoryResponse{Result: query})
|
||||
}
|
||||
|
||||
func (s *QueryHistoryService) migrateHandler(c *models.ReqContext) response.Response {
|
||||
cmd := MigrateQueriesToQueryHistoryCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
|
||||
totalCount, starredCount, err := s.MigrateQueriesToQueryHistory(c.Req.Context(), c.SignedInUser, cmd)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to migrate query history", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, QueryHistoryMigrationResponse{Message: "Query history successfully migrated", TotalCount: totalCount, StarredCount: starredCount})
|
||||
}
|
||||
|
Reference in New Issue
Block a user