gitea dump: include version & Check InstallLock (#12760)
* gitea dump: include version * Check InstallLock (close #12759) * fix test * fix lintrelease/v1.15
parent
226aef7e0f
commit
cfd8e8a489
|
@ -186,6 +186,10 @@ func runDump(ctx *cli.Context) error {
|
||||||
if _, err := setting.Cfg.Section("log.console").NewKey("STDERR", "true"); err != nil {
|
if _, err := setting.Cfg.Section("log.console").NewKey("STDERR", "true"); err != nil {
|
||||||
fatal("Setting console logger to stderr failed: %v", err)
|
fatal("Setting console logger to stderr failed: %v", err)
|
||||||
}
|
}
|
||||||
|
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()
|
||||||
|
|
|
@ -302,6 +302,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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in New Issue