Repository: syncthing/syncthing (language: go)

Issue:
"Running global migration to fix encryption file sizes" on every start
**Does your log mention database corruption?** No

### Required Information
**Version of Syncthing:** syncthing v1.23.3 "Fermium Flea"
**What Happened:** Syncthing will "Running global migration to fix encryption file sizes" on every start leaving syncthing unresponsive for over an hour with my 850GB encrypted folder set
**What you expected to happen:** Only run it once on the first occurrence
**Steps to reproduce the problem:**
1. Have a large encrypted folder set
2. Update to 1.23.3
3. Start syncthing
4. let it finish "Running global migration to fix encryption file sizes"
5. restart syncthing
6. it will once again "Running global migration to fix encryption file sizes"

### Possible heart of the issue
I am not a go developer, never had the pleasure, but if I am deciphering it correctly it looks like the migration function returns the result of the migration before it has a chance to update the "globalMigrationVersion" version to 1 ([line 39](https://github.com/syncthing/syncthing/blob/main/lib/syncthing/globalmigrations.go#L35-L39)) in the database so it will always run the encryptionTrailerSizeMigration function at startup (which is taking over an hour for my instance).

I have reverted to syncthing v1.23.2 which thankfully downgraded with no issue



Discussion / hints:
Yeah that looks like a bug sure enough

Fix patch:
diff --git a/lib/syncthing/globalmigrations.go b/lib/syncthing/globalmigrations.go
index 4b47936c5e7..1a38c5c8285 100644
--- a/lib/syncthing/globalmigrations.go
+++ b/lib/syncthing/globalmigrations.go
@@ -33,7 +33,9 @@ func globalMigration(ll *db.Lowlevel, cfg config.Wrapper) error {
 	}
 
 	if prevVersion < 1 {
-		return encryptionTrailerSizeMigration(ll, cfg)
+		if err := encryptionTrailerSizeMigration(ll, cfg); err != nil {
+			return err
+		}
 	}
 
 	return miscDB.PutInt64(globalMigrationDBKey, globalMigrationVersion)


Test patch: