bug fix for dump to postgres

This commit is contained in:
Lunny Xiao 2017-02-10 09:55:37 +08:00
parent 445a934d32
commit 19f6dfc2e8
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 8 additions and 0 deletions

View File

@ -521,6 +521,14 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
return err
}
}
// FIXME: Hack for postgres
if string(dialect.DBType()) == core.POSTGRES && table.AutoIncrColumn() != nil {
_, err = io.WriteString(w, "SELECT setval('table_id_seq', COALESCE((SELECT MAX("+table.AutoIncrColumn().Name+") FROM "+dialect.Quote(table.Name)+"), 1), false);\n")
if err != nil {
return err
}
}
}
return nil
}