MCPcopy
hub / github.com/hasura/graphql-engine / SquashCreateAPI

Function SquashCreateAPI

cli/migrate/api/squash.go:35–83  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

33}
34
35func SquashCreateAPI(c *gin.Context) {
36 migratePtr, ok := c.Get("migrate")
37 if !ok {
38 return
39 }
40
41 sourcePtr, ok := c.Get("filedir")
42 if !ok {
43 return
44 }
45
46 t := migratePtr.(*migrate.Migrate)
47 sourceURL := sourcePtr.(*url.URL)
48
49 var request squashCreateRequest
50 // Bind Request body to Request struct
51 if c.BindJSON(&request) != nil {
52 c.JSON(500, &Response{Code: "internal_error", Message: "Something went wrong"})
53 return
54 }
55 request.setDefaults()
56 // Rescan file system
57 err := t.ReScan()
58 if err != nil {
59 c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()})
60 return
61 }
62 if request.To == nil {
63 var v int64 = -1
64 request.To = &v
65 }
66 versions, err := cmd.SquashCmd(t, request.From, *request.To, request.version, request.Name, sourceURL.Path)
67 if err != nil {
68 if strings.HasPrefix(err.Error(), DataAPIError) {
69 c.JSON(http.StatusBadRequest, &Response{Code: "data_api_error", Message: strings.TrimPrefix(err.Error(), DataAPIError)})
70 return
71 }
72
73 if err == migrate.ErrNoMigrationMode {
74 c.JSON(http.StatusBadRequest, &Response{Code: "migration_mode_disabled", Message: err.Error()})
75 return
76 }
77
78 c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()})
79 return
80 }
81
82 c.JSON(http.StatusOK, gin.H{"version": request.version, "squashed_migrations": versions})
83}
84
85func SquashDeleteAPI(c *gin.Context) {
86 sourcePtr, ok := c.Get("filedir")

Callers

nothing calls this directly

Calls 5

setDefaultsMethod · 0.95
JSONMethod · 0.80
ReScanMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected