Avoid db errors while executing migrations check (#5072)

This commit is contained in:
Robert Kaussow 2025-04-04 14:24:02 +02:00 committed by GitHub
parent 009612d969
commit 9beb91828c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {