mirror of
https://github.com/beego/bee.git
synced 2024-11-22 15:10:54 +00:00
add downsql & controller add mapping
This commit is contained in:
parent
f97e13c5aa
commit
9faf04fea0
4
g.go
4
g.go
@ -158,10 +158,12 @@ func generateCode(cmd *Command, args []string) int {
|
|||||||
mname := args[1]
|
mname := args[1]
|
||||||
ColorLog("[INFO] Using '%s' as migration name\n", mname)
|
ColorLog("[INFO] Using '%s' as migration name\n", mname)
|
||||||
upsql := ""
|
upsql := ""
|
||||||
|
downsql := ""
|
||||||
if fields != "" {
|
if fields != "" {
|
||||||
upsql = `m.Sql("CREATE TABLE ` + mname + "(" + generateSQLFromFields(fields.String()) + `)");`
|
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":
|
case "controller":
|
||||||
if len(args) == 2 {
|
if len(args) == 2 {
|
||||||
cname := args[1]
|
cname := args[1]
|
||||||
|
@ -807,6 +807,14 @@ type {{ctrlName}}Controller struct {
|
|||||||
beego.Controller
|
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
|
// @Title Post
|
||||||
// @Description create {{ctrlName}}
|
// @Description create {{ctrlName}}
|
||||||
// @Param body body models.{{ctrlName}} true "body for {{ctrlName}} content"
|
// @Param body body models.{{ctrlName}} true "body for {{ctrlName}} content"
|
||||||
|
@ -68,6 +68,14 @@ type {{controllerName}}Controller struct {
|
|||||||
beego.Controller
|
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
|
// @Title Post
|
||||||
// @Description create {{controllerName}}
|
// @Description create {{controllerName}}
|
||||||
// @Param body body models.{{controllerName}} true "body for {{controllerName}} content"
|
// @Param body body models.{{controllerName}} true "body for {{controllerName}} content"
|
||||||
|
@ -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)
|
ColorLog("[INFO] Do you want me to create a %v migration and schema for this resource? [yes|no]] ", sname)
|
||||||
if askForConfirmation() {
|
if askForConfirmation() {
|
||||||
upsql := ""
|
upsql := ""
|
||||||
|
downsql := ""
|
||||||
if fields != "" {
|
if fields != "" {
|
||||||
upsql = `m.Sql("CREATE TABLE ` + sname + "(" + generateSQLFromFields(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
|
// run migration
|
||||||
ColorLog("[INFO] Do you want to go ahead and migrate the database? [yes|no]] ")
|
ColorLog("[INFO] Do you want to go ahead and migrate the database? [yes|no]] ")
|
||||||
|
Loading…
Reference in New Issue
Block a user