Skip noop migrations, instead of executing SELECT 0. (#103086)

* Skip noop migrations, instead of executing SELECT 0.
pull/103054/head
Peter Štibraný 4 months ago committed by GitHub
parent f0a6327edc
commit f7f28757f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      pkg/services/sqlstore/migrator/dialect.go
  2. 2
      pkg/services/sqlstore/migrator/migrations.go
  3. 5
      pkg/services/sqlstore/migrator/migrator.go

@ -74,7 +74,6 @@ type Dialect interface {
CleanDB(engine *xorm.Engine) error
TruncateDBTables(engine *xorm.Engine) error
NoOpSQL() string
// CreateDatabaseFromSnapshot is called when migration log table is not found.
// Dialect can recreate all tables from existing snapshot. After successful (nil error) return,
// migrator will list migrations from the log, and apply all missing migrations.
@ -353,10 +352,6 @@ func (b *BaseDialect) CreateDatabaseFromSnapshot(ctx context.Context, engine *xo
return nil
}
func (b *BaseDialect) NoOpSQL() string {
return "SELECT 0;"
}
func (b *BaseDialect) TruncateDBTables(engine *xorm.Engine) error {
return nil
}

@ -53,7 +53,7 @@ func (m *RawSQLMigration) SQL(dialect Dialect) string {
}
}
return dialect.NoOpSQL()
return ""
}
func (m *RawSQLMigration) Set(dialect string, sql string) *RawSQLMigration {

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"
_ "github.com/go-sql-driver/mysql"
@ -392,9 +393,13 @@ func (mg *Migrator) exec(ctx context.Context, m Migration, sess *xorm.Session) e
err = codeMigration.Exec(sess, mg)
} else {
sql := m.SQL(mg.Dialect)
if strings.TrimSpace(sql) == "" {
logger.Debug("Skipping empty sql migration", "id", m.Id())
} else {
logger.Debug("Executing sql migration", "id", m.Id(), "sql", sql)
_, err = sess.Exec(sql)
}
}
if err != nil {
logger.Error("Executing migration failed", "id", m.Id(), "error", err, "duration", time.Since(start))

Loading…
Cancel
Save