Skip to content

Commit 9513638

Browse files
6543CirnoT
andauthored
Prohibit automatic downgrades (#13108)
Prohibit automatic downgrades by checking the version of the db and warning if the version number should be lower. Close #13107 Co-authored-by: Cirno the Strongest <[email protected]>
1 parent c752cce commit 9513638

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
"reflect"
1112
"regexp"
1213
"strings"
@@ -315,12 +316,16 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
315316
return nil
316317
}
317318

319+
// Downgraded Gitea not supported
318320
if int(v-minDBVersion) > len(migrations) {
319-
// User downgraded Gitea.
320-
currentVersion.Version = int64(len(migrations) + minDBVersion)
321-
_, err = x.ID(1).Update(currentVersion)
322-
return err
321+
msg := fmt.Sprintf("Downgrading Gitea 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",
322+
v, minDBVersion+len(migrations), minDBVersion+len(migrations))
323+
fmt.Fprint(os.Stderr, msg)
324+
log.Fatal(msg)
325+
return nil
323326
}
327+
328+
// Migrate
324329
for i, m := range migrations[v-minDBVersion:] {
325330
log.Info("Migration[%d]: %s", v+int64(i), m.Description())
326331
if err = m.Migrate(x); err != nil {

0 commit comments

Comments
 (0)