Skip to content

Commit c5ec66a

Browse files
lunnyzeripath
authored andcommitted
fix dump table name error and add some test for dump database (#6394) (#6402)
1 parent b6fb082 commit c5ec66a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

models/models.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ type Engine interface {
5151
}
5252

5353
var (
54-
x *xorm.Engine
55-
tables []interface{}
54+
x *xorm.Engine
55+
supportedDatabases = []string{"mysql", "postgres", "mssql"}
56+
tables []interface{}
5657

5758
// HasEngine specifies if we have a xorm.Engine
5859
HasEngine bool
@@ -350,7 +351,9 @@ func Ping() error {
350351
func DumpDatabase(filePath string, dbType string) error {
351352
var tbs []*core.Table
352353
for _, t := range tables {
353-
tbs = append(tbs, x.TableInfo(t).Table)
354+
t := x.TableInfo(t)
355+
t.Table.Name = t.Name
356+
tbs = append(tbs, t.Table)
354357
}
355358
if len(dbType) > 0 {
356359
return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType))

models/models_sqlite.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ import (
1212

1313
func init() {
1414
EnableSQLite3 = true
15+
supportedDatabases = append(supportedDatabases, "sqlite3")
1516
}

models/models_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
package models
77

88
import (
9+
"io/ioutil"
10+
"os"
11+
"path/filepath"
912
"testing"
1013

1114
"github.com/stretchr/testify/assert"
@@ -93,3 +96,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) {
9396
assert.Equal(t, test.Output, connStr)
9497
}
9598
}
99+
100+
func TestDumpDatabase(t *testing.T) {
101+
assert.NoError(t, PrepareTestDatabase())
102+
103+
dir, err := ioutil.TempDir(os.TempDir(), "dump")
104+
assert.NoError(t, err)
105+
106+
for _, dbType := range supportedDatabases {
107+
assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))
108+
}
109+
}

0 commit comments

Comments
 (0)