klesh commented on code in PR #3135:
URL: https://github.com/apache/incubator-devlake/pull/3135#discussion_r975570217


##########
models/migrationscripts/20220913_commitfile_add_length.go:
##########
@@ -108,16 +136,40 @@ func (*addCommitFilePathLength) Up(ctx context.Context, 
db *gorm.DB) errors.Erro
 
                err = batch.Add(&cf)
                if err != nil {
-                       return errors.Default.Wrap(err, "error on batch add")
+                       return errors.Default.Wrap(err, "error on commit_files 
batch add")
                }
        }
 
+       // rename the commit_file_components_bak
        err = db.Migrator().RenameTable(&CommitFileComponent{}, 
&CommitFileComponentBak{})

Review Comment:
   same as above



##########
models/migrationscripts/20220913_commitfile_add_length.go:
##########
@@ -108,16 +136,40 @@ func (*addCommitFilePathLength) Up(ctx context.Context, 
db *gorm.DB) errors.Erro
 
                err = batch.Add(&cf)
                if err != nil {
-                       return errors.Default.Wrap(err, "error on batch add")
+                       return errors.Default.Wrap(err, "error on commit_files 
batch add")
                }
        }
 
+       // rename the commit_file_components_bak
        err = db.Migrator().RenameTable(&CommitFileComponent{}, 
&CommitFileComponentBak{})
+
+       // rollback for rename back
+       defer func() {
+               if errs != nil {
+                       err = 
db.Migrator().RenameTable(&CommitFileComponentBak{}, &CommitFileComponent{})
+                       if err != nil {
+                               errs = errors.Default.Wrap(err, 
fmt.Sprintf("fail to rollback table commit_file_components_bak , you must to 
rollback by yourself. %s", err.Error()))
+                       }
+               }
+       }()
+
        if err != nil {
                return errors.Default.Wrap(err, "error no rename 
commit_file_components to commit_file_components_bak")
        }
 
+       // create new commit_file_components table
        err = db.Migrator().AutoMigrate(&CommitFileComponent{})

Review Comment:
   same as above



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to