Skip to content

Commit e17e3f7

Browse files
authored
Use transaction in V102 migration (#12395)
The code for dropTableColumns has a slightly confusing portion whereby the session is committed for MSSQL but not for other variants. The v102 migration doesn't actually start a transaction so this weirdness does not affect it. However it probably should attempt to run this in a transaction. Signed-off-by: Andrew Thornton [email protected]
1 parent 8cd7e93 commit e17e3f7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

models/migrations/migrations.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,16 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
453453
tableName, strings.Replace(cols, "`", "'", -1))
454454
constraints := make([]string, 0)
455455
if err := sess.SQL(sql).Find(&constraints); err != nil {
456-
sess.Rollback()
457456
return fmt.Errorf("Find constraints: %v", err)
458457
}
459458
for _, constraint := range constraints {
460459
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP CONSTRAINT `%s`", tableName, constraint)); err != nil {
461-
sess.Rollback()
462460
return fmt.Errorf("Drop table `%s` constraint `%s`: %v", tableName, constraint, err)
463461
}
464462
}
465463
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP COLUMN %s", tableName, cols)); err != nil {
466-
sess.Rollback()
467464
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
468465
}
469-
return sess.Commit()
470466
default:
471467
log.Fatal("Unrecognized DB")
472468
}

models/migrations/v102.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ import (
1111
func dropColumnHeadUserNameOnPullRequest(x *xorm.Engine) error {
1212
sess := x.NewSession()
1313
defer sess.Close()
14-
return dropTableColumns(sess, "pull_request", "head_user_name")
14+
if err := sess.Begin(); err != nil {
15+
return err
16+
}
17+
if err := dropTableColumns(sess, "pull_request", "head_user_name"); err != nil {
18+
return err
19+
}
20+
return sess.Commit()
1521
}

0 commit comments

Comments
 (0)