fix cross db dumping of bools
When dumping booleans these need to be converted from the original DB representation to the new db representation. In the case of most DBs this is simply to 0 or 1 but for postgres these have to be false or true. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
57365108ae
commit
48b120638f
22
engine.go
22
engine.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -438,16 +439,14 @@ func (engine *Engine) DumpTables(tables []*schemas.Table, w io.Writer, tp ...sch
|
||||||
return engine.dumpTables(context.Background(), tables, w, tp...)
|
return engine.dumpTables(context.Background(), tables, w, tp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatBool(s string, dstDialect dialects.Dialect) string {
|
func formatBool(s bool, dstDialect dialects.Dialect) string {
|
||||||
if dstDialect.URI().DBType == schemas.MSSQL {
|
if dstDialect.URI().DBType != schemas.POSTGRES {
|
||||||
switch s {
|
if s {
|
||||||
case "true":
|
|
||||||
return "1"
|
return "1"
|
||||||
case "false":
|
|
||||||
return "0"
|
|
||||||
}
|
}
|
||||||
|
return "0"
|
||||||
}
|
}
|
||||||
return s
|
return strconv.FormatBool(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dumpTables dump database all table structs and data to w with specify db type
|
// dumpTables dump database all table structs and data to w with specify db type
|
||||||
|
@ -581,8 +580,13 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if stp.IsBool() || (dstDialect.URI().DBType == schemas.MSSQL && strings.EqualFold(stp.Name, schemas.Bit)) {
|
if table.Columns()[i].SQLType.IsBool() || stp.IsBool() || (dstDialect.URI().DBType == schemas.MSSQL && strings.EqualFold(stp.Name, schemas.Bit)) {
|
||||||
if _, err = io.WriteString(w, formatBool(s.String, dstDialect)); err != nil {
|
val, err := strconv.ParseBool(s.String)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = io.WriteString(w, formatBool(val, dstDialect)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if stp.IsNumeric() {
|
} else if stp.IsNumeric() {
|
||||||
|
|
Loading…
Reference in New Issue