klesh commented on code in PR #3135:
URL: https://github.com/apache/incubator-devlake/pull/3135#discussion_r975566169
##########
models/migrationscripts/20220913_commitfile_add_length.go:
##########
@@ -67,13 +68,39 @@ func (CommitFileComponentBak) TableName() string {
type addCommitFilePathLength struct{}
-func (*addCommitFilePathLength) Up(ctx context.Context, db *gorm.DB)
errors.Error {
- err := db.Migrator().RenameTable(&CommitFile{},
&CommitFileAddLengthBak{})
+func (*addCommitFilePathLength) Up(ctx context.Context, db *gorm.DB) (errs
errors.Error) {
+ var err error
+
+ // rename the commit_file_bak to cache old table
+ err = db.Migrator().RenameTable(&CommitFile{},
&CommitFileAddLengthBak{})
Review Comment:
shouldn't we return here if the error is not nil?
##########
models/migrationscripts/20220913_commitfile_add_length.go:
##########
@@ -67,13 +68,39 @@ func (CommitFileComponentBak) TableName() string {
type addCommitFilePathLength struct{}
-func (*addCommitFilePathLength) Up(ctx context.Context, db *gorm.DB)
errors.Error {
- err := db.Migrator().RenameTable(&CommitFile{},
&CommitFileAddLengthBak{})
+func (*addCommitFilePathLength) Up(ctx context.Context, db *gorm.DB) (errs
errors.Error) {
+ var err error
+
+ // rename the commit_file_bak to cache old table
+ err = db.Migrator().RenameTable(&CommitFile{},
&CommitFileAddLengthBak{})
+
+ // rollback for rename back
+ defer func() {
+ if errs != nil {
+ err =
db.Migrator().RenameTable(&CommitFileAddLengthBak{}, &CommitFile{})
+ if err != nil {
+ errs = errors.Default.Wrap(err,
fmt.Sprintf("fail to rollback table commit_file_bak , you must to rollback by
yourself. %s", err.Error()))
+ }
+ }
+ }()
+
if err != nil {
return errors.Default.Wrap(err, "error no rename commit_file to
commit_files_bak")
}
+ // create new commit_files table
err = db.Migrator().AutoMigrate(&CommitFileAddLength{})
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]