Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dump table name error and add some test for dump database #6394

Merged
merged 4 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ type Engine interface {
}

var (
x *xorm.Engine
tables []interface{}
x *xorm.Engine
supportedDatabse = []string{"mysql", "postgres", "mssql"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo nit, should be supportedDatabase or supportedDatabases and refactored as needed where used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. It's strange that misspell check failed.

tables []interface{}

// HasEngine specifies if we have a xorm.Engine
HasEngine bool
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions models/models_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ import (

func init() {
EnableSQLite3 = true
supportedDatabse = append(supportedDatabse, "sqlite3")
}
14 changes: 14 additions & 0 deletions models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package models

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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))
}
}