refactor generate migration

This commit is contained in:
Sergey Lanzman
2016-07-23 21:05:44 +03:00
parent f8447477d9
commit 3627eb2ddc
3 changed files with 166 additions and 121 deletions

8
g.go
View File

@ -170,11 +170,9 @@ func generateCode(cmd *Command, args []string) int {
upsql := ""
downsql := ""
if fields != "" {
upsql = `m.SQL("CREATE TABLE ` + mname + "(" + generateSQLFromFields(fields.String()) + `)");`
downsql = `m.SQL("DROP TABLE ` + "`" + mname + "`" + `")`
if driver == "postgres" {
downsql = strings.Replace(downsql, "`", "", -1)
}
dbMigrator := newDBDriver()
upsql = dbMigrator.generateCreateUp(mname)
downsql = dbMigrator.generateCreateDown(mname)
}
generateMigration(mname, upsql, downsql, currpath)
case "controller":