Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: remove migration files if api returns error (close #4312) #4319

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The order and collapsed state of columns is now persisted across page navigation

### Bug fixes and improvements

- cli: clean up migration files created during a failed migrate api (close #4312) (#4319)
- cli: add support for multiple versions of plugin (close #4105)
- cli: template assets path in console HTML for unversioned builds
- console: allow customising graphql field names for columns of views (close #3689) (#4255)
Expand Down
36 changes: 14 additions & 22 deletions cli/migrate/api/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ func MigrateAPI(c *gin.Context) {
c.JSON(http.StatusOK, status)
case "POST":
var request Request
var err error

// Bind Request body to Request struct
if err := c.BindJSON(&request); err != nil {
if err = c.BindJSON(&request); err != nil {
c.JSON(http.StatusInternalServerError, &Response{Code: "request_parse_error", Message: err.Error()})
return
}
Expand Down Expand Up @@ -135,40 +136,31 @@ func MigrateAPI(c *gin.Context) {
}

if sqlUp.String() != "" {
err := createOptions.SetSQLUp(sqlUp.String())
err = createOptions.SetSQLUp(sqlUp.String())
if err != nil {
c.JSON(http.StatusInternalServerError, &Response{Code: "create_file_error", Message: err.Error()})
return
}
}
if sqlDown.String() != "" {
err := createOptions.SetSQLDown(sqlDown.String())
err = createOptions.SetSQLDown(sqlDown.String())
if err != nil {
c.JSON(http.StatusInternalServerError, &Response{Code: "create_file_error", Message: err.Error()})
return
}
}

if sqlUp.String() != "" || sqlDown.String() != "" {
err := createOptions.Create()
err = createOptions.Create()
if err != nil {
c.JSON(http.StatusInternalServerError, &Response{Code: "create_file_error", Message: err.Error()})
return
}

defer func() {
if err != nil {
err := createOptions.Delete()
if err != nil {
logger.Debug(err)
}
}
}()
} else {
timestamp = 0
}
} else {
err := createOptions.SetMetaUp(request.Up)
err = createOptions.SetMetaUp(request.Up)
if err != nil {
c.JSON(http.StatusInternalServerError, &Response{Code: "create_file_error", Message: err.Error()})
return
Expand All @@ -184,19 +176,19 @@ func MigrateAPI(c *gin.Context) {
c.JSON(http.StatusInternalServerError, &Response{Code: "create_file_error", Message: err.Error()})
return
}
}

defer func() {
defer func() {
if err != nil && timestamp != 0 {
err := createOptions.Delete()
if err != nil {
err = createOptions.Delete()
if err != nil {
logger.Debug(err)
}
logger.Debug(err)
}
}()
}
}
}()

// Rescan file system
err := t.ReScan()
err = t.ReScan()
if err != nil {
c.JSON(http.StatusInternalServerError, &Response{Code: "internal_error", Message: err.Error()})
return
Expand Down