Skip to content

Commit 4a67bb5

Browse files
committed
migrations.v17: skip if table not exist
1 parent 1afafde commit 4a67bb5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

models/migrations/v17.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
package migrations
66

77
import (
8-
"strings"
8+
"fmt"
99

1010
"github.com/go-xorm/xorm"
1111
)
1212

1313
func removeInvalidProtectBranchWhitelist(x *xorm.Engine) error {
14-
_, err := x.Exec("DELETE FROM protect_branch_whitelist WHERE protect_branch_id = 0")
15-
if err != nil && (strings.Contains(err.Error(), "no such table") || strings.Contains(err.Error(), "doesn't exist")) {
14+
exist, err := x.IsTableExist("protect_branch_whitelist")
15+
if err != nil {
16+
return fmt.Errorf("IsTableExist: %v", err)
17+
} else if !exist {
1618
return nil
1719
}
20+
_, err = x.Exec("DELETE FROM protect_branch_whitelist WHERE protect_branch_id = 0")
1821
return err
1922
}

0 commit comments

Comments
 (0)