diff --git a/engine.go b/engine.go index 52865a3b..4694e1c0 100644 --- a/engine.go +++ b/engine.go @@ -375,6 +375,10 @@ func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...sch if dstDialect.URI().Schema != "" { tableName = fmt.Sprintf("%s.%s", dstDialect.URI().Schema, table.Name) } + originalTableName := table.Name + if engine.dialect.URI().Schema != "" { + originalTableName = fmt.Sprintf("%s.%s", engine.dialect.URI().Schema, table.Name) + } if i > 0 { _, err = io.WriteString(w, "\n") if err != nil { @@ -403,7 +407,7 @@ func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...sch colNames := engine.dialect.Quoter().Join(cols, ", ") destColNames := dstDialect.Quoter().Join(cols, ", ") - rows, err := engine.DB().QueryContext(engine.defaultContext, "SELECT "+colNames+" FROM "+engine.Quote(tableName)) + rows, err := engine.DB().QueryContext(engine.defaultContext, "SELECT "+colNames+" FROM "+engine.Quote(originalTableName)) if err != nil { return err } diff --git a/engine_test.go b/engine_test.go index ab454d0d..d6da5f33 100644 --- a/engine_test.go +++ b/engine_test.go @@ -97,6 +97,12 @@ func TestDump(t *testing.T) { _, err := sess.ImportFile(fp) assert.NoError(t, err) assert.NoError(t, sess.Commit()) + + for _, tp := range []schemas.DBType{schemas.SQLITE, schemas.MYSQL, schemas.POSTGRES, schemas.MSSQL} { + t.Run(fmt.Sprintf("dump_%v", tp), func(t *testing.T) { + assert.NoError(t, testEngine.DumpAllToFile(fp, tp)) + }) + } } func TestSetSchema(t *testing.T) {