From 91dcccf72d15d9d6dbe9c0cc5c5d33c082225cde Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 21 Mar 2019 09:38:54 +0800 Subject: fix dump table name error and add some test for dump database (#6394) --- models/models.go | 9 ++++++--- models/models_sqlite.go | 1 + models/models_test.go | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/models/models.go b/models/models.go index ac7e2e93ba..e7ecc67fc5 100644 --- a/models/models.go +++ b/models/models.go @@ -51,8 +51,9 @@ type Engine interface { } var ( - x *xorm.Engine - tables []interface{} + x *xorm.Engine + supportedDatabases = []string{"mysql", "postgres", "mssql"} + tables []interface{} // HasEngine specifies if we have a xorm.Engine HasEngine bool @@ -350,7 +351,9 @@ func Ping() error { func DumpDatabase(filePath string, dbType string) error { var tbs []*core.Table for _, t := range tables { - tbs = append(tbs, x.TableInfo(t).Table) + t := x.TableInfo(t) + t.Table.Name = t.Name + tbs = append(tbs, t.Table) } if len(dbType) > 0 { return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType)) diff --git a/models/models_sqlite.go b/models/models_sqlite.go index c77e5ae5a6..3889aceb84 100644 --- a/models/models_sqlite.go +++ b/models/models_sqlite.go @@ -12,4 +12,5 @@ import ( func init() { EnableSQLite3 = true + supportedDatabases = append(supportedDatabases, "sqlite3") } diff --git a/models/models_test.go b/models/models_test.go index 7016fdb4b7..6df3b4e048 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -6,6 +6,9 @@ package models import ( + "io/ioutil" + "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -93,3 +96,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) { assert.Equal(t, test.Output, connStr) } } + +func TestDumpDatabase(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + dir, err := ioutil.TempDir(os.TempDir(), "dump") + assert.NoError(t, err) + + for _, dbType := range supportedDatabases { + assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType)) + } +} -- cgit v1.2.3