diff --git a/g.go b/g.go index 187e4d6..750580c 100644 --- a/g.go +++ b/g.go @@ -158,10 +158,12 @@ func generateCode(cmd *Command, args []string) int { mname := args[1] ColorLog("[INFO] Using '%s' as migration name\n", mname) upsql := "" + downsql := "" if fields != "" { upsql = `m.Sql("CREATE TABLE ` + mname + "(" + generateSQLFromFields(fields.String()) + `)");` + downsql = `m.Sql("DROP TABLE ` + "`" + mname + "`" + `")` } - generateMigration(mname, upsql, "", curpath) + generateMigration(mname, upsql, downsql, curpath) case "controller": if len(args) == 2 { cname := args[1] diff --git a/g_appcode.go b/g_appcode.go index 6a5ba3a..d6124d9 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -807,6 +807,14 @@ type {{ctrlName}}Controller struct { beego.Controller } +func (this *{{ctrlName}}Controller) URLMapping() { + this.Mapping("Post", this.Post) + this.Mapping("GetOne", this.GetOne) + this.Mapping("GetAll", this.GetAll) + this.Mapping("Put", this.Put) + this.Mapping("Delete", this.Delete) +} + // @Title Post // @Description create {{ctrlName}} // @Param body body models.{{ctrlName}} true "body for {{ctrlName}} content" diff --git a/g_controllers.go b/g_controllers.go index e176d86..22c3c9c 100644 --- a/g_controllers.go +++ b/g_controllers.go @@ -68,6 +68,14 @@ type {{controllerName}}Controller struct { beego.Controller } +func (this *{{controllerName}}Controller) URLMapping() { + this.Mapping("Post", this.Post) + this.Mapping("GetOne", this.GetOne) + this.Mapping("GetAll", this.GetAll) + this.Mapping("Put", this.Put) + this.Mapping("Delete", this.Delete) +} + // @Title Post // @Description create {{controllerName}} // @Param body body models.{{controllerName}} true "body for {{controllerName}} content" diff --git a/g_scaffold.go b/g_scaffold.go index 44406bf..1d0c239 100644 --- a/g_scaffold.go +++ b/g_scaffold.go @@ -26,10 +26,12 @@ func generateScaffold(sname, fields, crupath, driver, conn string) { ColorLog("[INFO] Do you want me to create a %v migration and schema for this resource? [yes|no]] ", sname) if askForConfirmation() { upsql := "" + downsql := "" if fields != "" { upsql = `m.Sql("CREATE TABLE ` + sname + "(" + generateSQLFromFields(fields) + `)");` + downsql = `m.Sql("DROP TABLE ` + "`" + sname + "`" + `")` } - generateMigration(sname, upsql, "", crupath) + generateMigration(sname, upsql, downsql, crupath) } // run migration ColorLog("[INFO] Do you want to go ahead and migrate the database? [yes|no]] ")