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

Function MigrateAPI

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

Source from the content-addressed store, hash-verified

51}
52
53func 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()})

Callers

nothing calls this directly

Calls 15

ReScanMethod · 0.95
GetStatusMethod · 0.95
QueryWithVersionMethod · 0.95
JSONMethod · 0.80
SetSQLUpMethod · 0.80
SetSQLDownMethod · 0.80
GetMethod · 0.65
QueryMethod · 0.65
ExportMetadataMethod · 0.65
ErrorMethod · 0.45
MarshalMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected