log skipped, performed and duration for migrations (#31722)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist 2021-03-07 21:26:29 +01:00 committed by GitHub
parent ab2f405205
commit c899bf3592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,11 +79,15 @@ func (mg *Migrator) Start() error {
return err
}
migrationsPerformed := 0
migrationsSkipped := 0
start := time.Now()
for _, m := range mg.migrations {
m := m
_, exists := logMap[m.Id()]
if exists {
mg.Logger.Debug("Skipping migration: Already executed", "id", m.Id())
migrationsSkipped++
continue
}
@ -107,6 +111,9 @@ func (mg *Migrator) Start() error {
}
record.Success = true
_, err = sess.Insert(&record)
if err == nil {
migrationsPerformed++
}
return err
})
if err != nil {
@ -114,6 +121,8 @@ func (mg *Migrator) Start() error {
}
}
mg.Logger.Info("migrations completed", "performed", migrationsPerformed, "skipped", migrationsSkipped, "duration", time.Since(start))
// Make sure migrations are synced
return mg.x.Sync2()
}