(c *gin.Context)
| 51 | } |
| 52 | |
| 53 | func MigrateAPI(c *gin.Context) { |
| 54 | ecPtr, ok := c.Get("ec") |
| 55 | if !ok { |
| 56 | return |
| 57 | } |
| 58 | // Get File url |
| 59 | //sourcePtr, ok := c.Get("filedir") |
| 60 | if !ok { |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | // Get Logger |
| 65 | loggerPtr, ok := c.Get("logger") |
| 66 | if !ok { |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | // Convert to url.URL |
| 71 | ec, ok := ecPtr.(*cli.ExecutionContext) |
| 72 | if !ok { |
| 73 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: "cannot get execution context"}) |
| 74 | return |
| 75 | } |
| 76 | //sourceURL := sourcePtr.(*url.URL) |
| 77 | logger := loggerPtr.(*logrus.Logger) |
| 78 | |
| 79 | mdHandler := projectmetadata.NewHandlerFromEC(ec) |
| 80 | // Switch on request method |
| 81 | switch c.Request.Method { |
| 82 | case "GET": |
| 83 | sourceName := c.Query("datasource") |
| 84 | if ec.Config.Version >= cli.V3 && sourceName == "" { |
| 85 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: "datasource query parameter is required"}) |
| 86 | return |
| 87 | } |
| 88 | sourceKind := hasura.SourceKindPG |
| 89 | if ec.Config.Version >= cli.V3 { |
| 90 | kind, err := metadatautil.GetSourceKind(ec.APIClient.V1Metadata.ExportMetadata, sourceName) |
| 91 | if err != nil { |
| 92 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) |
| 93 | return |
| 94 | } |
| 95 | if kind == nil { |
| 96 | c.JSON(http.StatusInternalServerError, &Response{Code: "request_parse_error", Message: fmt.Sprintf("cannot determine database kind for '%v'", sourceName)}) |
| 97 | return |
| 98 | } |
| 99 | sourceKind = *kind |
| 100 | } |
| 101 | |
| 102 | t, err := migrate.NewMigrate(ec, false, sourceName, sourceKind) |
| 103 | if err != nil { |
| 104 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) |
| 105 | return |
| 106 | } |
| 107 | // Rescan file system |
| 108 | err = t.ReScan() |
| 109 | if err != nil { |
| 110 | c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()}) |
nothing calls this directly
no test coverage detected