mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 12:14:10 +01:00
fix dump table name error and add some test for dump database (#6394)
This commit is contained in:
parent
75601a8cbc
commit
91dcccf72d
3 changed files with 21 additions and 3 deletions
|
@ -52,6 +52,7 @@ type Engine interface {
|
||||||
|
|
||||||
var (
|
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 specifies if we have a xorm.Engine
|
||||||
|
@ -350,7 +351,9 @@ func Ping() error {
|
||||||
func DumpDatabase(filePath string, dbType string) error {
|
func DumpDatabase(filePath string, dbType string) error {
|
||||||
var tbs []*core.Table
|
var tbs []*core.Table
|
||||||
for _, t := range tables {
|
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 {
|
if len(dbType) > 0 {
|
||||||
return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType))
|
return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType))
|
||||||
|
|
|
@ -12,4 +12,5 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
EnableSQLite3 = true
|
EnableSQLite3 = true
|
||||||
|
supportedDatabases = append(supportedDatabases, "sqlite3")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -93,3 +96,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) {
|
||||||
assert.Equal(t, test.Output, connStr)
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue