瀏覽代碼

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

* gitea dump: include version

* Check InstallLock
tags/v1.12.5
6543 3 年之前
父節點
當前提交
7a25441abe
沒有連結到貢獻者的電子郵件帳戶。
共有 3 個檔案被更改,包括 21 行新增0 行删除
  1. 4
    0
      cmd/dump.go
  2. 11
    0
      models/models.go
  3. 6
    0
      models/models_test.go

+ 4
- 0
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()

+ 11
- 0
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))
}

+ 6
- 0
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))

Loading…
取消
儲存