Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit a6300f2

Browse files
gzsomborlunny
authored andcommitted
Fixing issue from go-gitea/gitea #5728 (#1192)
* Format boolean values to true/false even when it is returned as byte-slice, * Fix the sequence generation, the proper sequence name is used (instead of 'table_id_seq'), and fix the next value be max+1 always
1 parent 1cd2662 commit a6300f2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

engine.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,11 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
527527
} else if col.SQLType.IsNumeric() {
528528
switch reflect.TypeOf(d).Kind() {
529529
case reflect.Slice:
530-
temp += fmt.Sprintf(", %s", string(d.([]byte)))
530+
if col.SQLType.Name == core.Bool {
531+
temp += fmt.Sprintf(", %v", strconv.FormatBool(d.([]byte)[0] != byte('0')))
532+
} else {
533+
temp += fmt.Sprintf(", %s", string(d.([]byte)))
534+
}
531535
case reflect.Int16, reflect.Int8, reflect.Int32, reflect.Int64, reflect.Int:
532536
if col.SQLType.Name == core.Bool {
533537
temp += fmt.Sprintf(", %v", strconv.FormatBool(reflect.ValueOf(d).Int() > 0))
@@ -564,7 +568,7 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
564568

565569
// FIXME: Hack for postgres
566570
if string(dialect.DBType()) == core.POSTGRES && table.AutoIncrColumn() != nil {
567-
_, err = io.WriteString(w, "SELECT setval('table_id_seq', COALESCE((SELECT MAX("+table.AutoIncrColumn().Name+") FROM "+dialect.Quote(table.Name)+"), 1), false);\n")
571+
_, err = io.WriteString(w, "SELECT setval('"+table.Name+"_id_seq', COALESCE((SELECT MAX("+table.AutoIncrColumn().Name+") + 1 FROM "+dialect.Quote(table.Name)+"), 1), false);\n")
568572
if err != nil {
569573
return err
570574
}

0 commit comments

Comments
 (0)