From 9ae39d6d58caa2b7daf2d6c3400a73f6b67fd21c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 20 Mar 2019 21:18:25 +0800 Subject: [PATCH 1/3] fix dump table name error and add some test for dump database --- 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 ac7e2e93bab9f..1b3125cfba6d6 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 + supportedDatabse = []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 c77e5ae5a6644..4e4792cb7ab3e 100644 --- a/models/models_sqlite.go +++ b/models/models_sqlite.go @@ -12,4 +12,5 @@ import ( func init() { EnableSQLite3 = true + supportedDatabse = append(supportedDatabse, "sqlite3") } diff --git a/models/models_test.go b/models/models_test.go index 7016fdb4b75bf..3183a3ac2198c 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 supportedDatabse { + assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType)) + } +} From 0026824de13122ae22b534fd7d57442df56203a3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 20 Mar 2019 22:41:01 +0800 Subject: [PATCH 2/3] fix typo --- models/models.go | 2 +- models/models_sqlite.go | 2 +- models/models_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/models.go b/models/models.go index 1b3125cfba6d6..67c24b2b02d36 100644 --- a/models/models.go +++ b/models/models.go @@ -52,7 +52,7 @@ type Engine interface { var ( x *xorm.Engine - supportedDatabse = []string{"mysql", "postgres", "mssql"} + supportedDatabases = []string{"mysql", "postgres", "mssql"} tables []interface{} // HasEngine specifies if we have a xorm.Engine diff --git a/models/models_sqlite.go b/models/models_sqlite.go index 4e4792cb7ab3e..3889aceb847d1 100644 --- a/models/models_sqlite.go +++ b/models/models_sqlite.go @@ -12,5 +12,5 @@ import ( func init() { EnableSQLite3 = true - supportedDatabse = append(supportedDatabse, "sqlite3") + supportedDatabases = append(supportedDatabases, "sqlite3") } diff --git a/models/models_test.go b/models/models_test.go index 3183a3ac2198c..6df3b4e04864b 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -103,7 +103,7 @@ func TestDumpDatabase(t *testing.T) { dir, err := ioutil.TempDir(os.TempDir(), "dump") assert.NoError(t, err) - for _, dbType := range supportedDatabse { + for _, dbType := range supportedDatabases { assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType)) } } From 2c8f17ed28f2e430d05fb78d87d0efa9bbee721c Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Wed, 20 Mar 2019 21:20:35 -0400 Subject: [PATCH 3/3] make fmt --- models/models.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/models.go b/models/models.go index 67c24b2b02d36..e7ecc67fc5538 100644 --- a/models/models.go +++ b/models/models.go @@ -51,9 +51,9 @@ type Engine interface { } var ( - x *xorm.Engine + x *xorm.Engine supportedDatabases = []string{"mysql", "postgres", "mssql"} - tables []interface{} + tables []interface{} // HasEngine specifies if we have a xorm.Engine HasEngine bool