gitea dump: include version & Check InstallLock (#12760) (#12762)

* gitea dump: include version

* Check InstallLock
This commit is contained in:
6543 2020-09-08 02:44:45 +02:00 committed by GitHub
parent dc71d00393
commit 7a25441abe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -66,6 +66,10 @@ func fatal(format string, args ...interface{}) {
func runDump(ctx *cli.Context) error { func runDump(ctx *cli.Context) error {
setting.NewContext() 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 setting.NewServices() // cannot access session settings otherwise
err := models.SetEngine() err := models.SetEngine()

View file

@ -264,6 +264,17 @@ func DumpDatabase(filePath string, dbType string) error {
} }
tbs = append(tbs, t) 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 { if len(dbType) > 0 {
return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType)) return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType))
} }

View file

@ -21,6 +21,12 @@ func TestDumpDatabase(t *testing.T) {
dir, err := ioutil.TempDir(os.TempDir(), "dump") dir, err := ioutil.TempDir(os.TempDir(), "dump")
assert.NoError(t, err) 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 { for _, dbName := range setting.SupportedDatabases {
dbType := setting.GetDBTypeByName(dbName) dbType := setting.GetDBTypeByName(dbName)
assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType)) assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))