From 54ffaac9c567c6bf925e2ffad44c9348925085c4 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Thu, 27 Aug 2026 16:19:03 +0800 Subject: [PATCH] =?UTF-8?q?chore=F0=9F=94=A7:=20say=20which=20migration=20?= =?UTF-8?q?is=20running,=20not=20a=20column=20of=20ones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An applied migration printed its count - a bare '1' - so a database with seven of them wrote seven lines of '1' at every start, and a failure said only which error, never which migration. It now names each one as it applies, reports the total, and says so when there is nothing to do. --- cmd/migrate/migration/init.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/migrate/migration/init.go b/cmd/migrate/migration/init.go index 739e6b40..28f48e0d 100644 --- a/cmd/migrate/migration/init.go +++ b/cmd/migrate/migration/init.go @@ -43,20 +43,28 @@ func (e *Migration) Migrate() { } var err error var count int64 + applied := 0 for _, v := range versions { err = e.db.Table("sys_migration").Where("version = ?", v).Count(&count).Error if err != nil { log.Fatalln(err) } if count > 0 { - log.Println(count) + // Already applied. This used to print the bare count, so a mature + // database wrote a screen of "1" at every start. count = 0 continue } - err = (e.version[v])(e.db.Debug(), v) - if err != nil { - log.Fatalln(err) + log.Printf("applying migration %s", v) + if err = (e.version[v])(e.db.Debug(), v); err != nil { + log.Fatalf("migration %s failed: %v", v, err) } + applied++ + } + if applied == 0 { + log.Println("no migrations to apply") + } else { + log.Printf("applied %d migration(s)", applied) } }