From 7a25441abe00efbebd68a479762520dc3610018c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 8 Sep 2020 02:44:45 +0200 Subject: [PATCH] gitea dump: include version & Check InstallLock (#12760) (#12762) * gitea dump: include version * Check InstallLock --- cmd/dump.go | 4 ++++ models/models.go | 11 +++++++++++ models/models_test.go | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/cmd/dump.go b/cmd/dump.go index 774b1d5d50..93f2f7aac1 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -66,6 +66,10 @@ func fatal(format string, args ...interface{}) { func runDump(ctx *cli.Context) error { setting.NewContext() + if !setting.InstallLock { + log.Error("Is '%s' really the right config path?\n", setting.CustomConf) + return fmt.Errorf("gitea is not initialized") + } setting.NewServices() // cannot access session settings otherwise err := models.SetEngine() diff --git a/models/models.go b/models/models.go index 7f12d6260a..af5835d59d 100644 --- a/models/models.go +++ b/models/models.go @@ -264,6 +264,17 @@ func DumpDatabase(filePath string, dbType string) error { } tbs = append(tbs, t) } + + type Version struct { + ID int64 `xorm:"pk autoincr"` + Version int64 + } + t, err := x.TableInfo(Version{}) + if err != nil { + return err + } + tbs = append(tbs, t) + if len(dbType) > 0 { return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType)) } diff --git a/models/models_test.go b/models/models_test.go index 37e9a352f8..2441ad7fb0 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -21,6 +21,12 @@ func TestDumpDatabase(t *testing.T) { dir, err := ioutil.TempDir(os.TempDir(), "dump") assert.NoError(t, err) + type Version struct { + ID int64 `xorm:"pk autoincr"` + Version int64 + } + assert.NoError(t, x.Sync2(Version{})) + for _, dbName := range setting.SupportedDatabases { dbType := setting.GetDBTypeByName(dbName) assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))