mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-14 07:44:12 +00:00
Avoid db errors while executing migrations check (#5072)
This commit is contained in:
parent
009612d969
commit
9beb91828c
1 changed files with 15 additions and 2 deletions
|
@ -83,8 +83,21 @@ func Migrate(_ context.Context, e *xorm.Engine, allowLong bool) error {
|
|||
|
||||
m := xormigrate.New(e, migrationTasks)
|
||||
m.AllowLong(allowLong)
|
||||
oldCount, err := e.Table("migrations").Count()
|
||||
if oldCount < 1 || err != nil {
|
||||
|
||||
oldExist, err := e.IsTableExist("migrations")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
oldEmpty := false
|
||||
if oldExist {
|
||||
oldEmpty, err = e.IsTableEmpty("migrations")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !oldExist || oldEmpty {
|
||||
// allow new schema initialization if old migrations table is empty or it does not exist (err != nil)
|
||||
// schema initialization will always run if we call `InitSchema`
|
||||
m.InitSchema(func(_ *xorm.Engine) error {
|
||||
|
|
Loading…
Reference in a new issue