Skip to content

Commit e0ae0b3

Browse files
6543zeripathCirnoT
authored
[Backport] Prohibit automatic downgrades (#13108) (#13111)
* Prohibit automatic downgrades * do not only log, print to stderr too * Update models/migrations/migrations.go * Update models/migrations/migrations.go Co-authored-by: Cirno the Strongest <[email protected]> * a nit Co-authored-by: zeripath <[email protected]> Co-authored-by: Cirno the Strongest <[email protected]>
1 parent f9942ad commit e0ae0b3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

models/migrations/migrations.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package migrations
77

88
import (
99
"fmt"
10+
"os"
1011
"regexp"
1112
"strings"
1213

@@ -290,12 +291,16 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
290291
return nil
291292
}
292293

294+
// Downgrading Gitea's database version not supported
293295
if int(v-minDBVersion) > len(migrations) {
294-
// User downgraded Gitea.
295-
currentVersion.Version = int64(len(migrations) + minDBVersion)
296-
_, err = x.ID(1).Update(currentVersion)
297-
return err
296+
msg := fmt.Sprintf("Downgrading database version from '%d' to '%d' is not supported and may result in loss of data integrity.\nIf you really know what you're doing, execute `UPDATE version SET version=%d WHERE id=1;`\n",
297+
v, minDBVersion+len(migrations), minDBVersion+len(migrations))
298+
fmt.Fprint(os.Stderr, msg)
299+
log.Fatal(msg)
300+
return nil
298301
}
302+
303+
// Migrate
299304
for i, m := range migrations[v-minDBVersion:] {
300305
log.Info("Migration[%d]: %s", v+int64(i), m.Description())
301306
if err = m.Migrate(x); err != nil {

0 commit comments

Comments
 (0)