bee/g_scaffold.go

49 lines
1.4 KiB
Go
Raw Normal View History

2014-08-11 09:01:00 +00:00
package main
2016-07-23 18:05:44 +00:00
import "strings"
2014-08-11 09:01:00 +00:00
func generateScaffold(sname, fields, currpath, driver, conn string) {
ColorLog("[INFO] Do you want to create a '%v' model? [Yes|No] ", sname)
// Generate the model
2014-08-11 09:01:00 +00:00
if askForConfirmation() {
generateModel(sname, fields, currpath)
2014-08-11 09:01:00 +00:00
}
// Generate the controller
ColorLog("[INFO] Do you want to create a '%v' controller? [Yes|No] ", sname)
2014-08-11 09:01:00 +00:00
if askForConfirmation() {
generateController(sname, currpath)
2014-08-11 09:01:00 +00:00
}
// Generate the views
ColorLog("[INFO] Do you want to create views for this '%v' resource? [Yes|No] ", sname)
2014-08-11 09:01:00 +00:00
if askForConfirmation() {
generateView(sname, currpath)
2014-08-11 09:01:00 +00:00
}
// Generate a migration
ColorLog("[INFO] Do you want to create a '%v' migration and schema for this resource? [Yes|No] ", sname)
2014-08-11 09:01:00 +00:00
if askForConfirmation() {
2014-08-18 03:51:57 +00:00
upsql := ""
2014-08-18 04:21:21 +00:00
downsql := ""
2014-08-18 03:51:57 +00:00
if fields != "" {
2016-07-23 18:05:44 +00:00
dbMigrator := newDBDriver()
upsql = dbMigrator.generateCreateUp(sname)
downsql = dbMigrator.generateCreateDown(sname)
//todo remove
//if driver == "" {
// downsql = strings.Replace(downsql, "`", "", -1)
//}
2014-08-18 03:51:57 +00:00
}
generateMigration(sname, upsql, downsql, currpath)
2014-08-11 09:01:00 +00:00
}
// Run the migration
ColorLog("[INFO] Do you want to migrate the database? [Yes|No] ")
2014-08-11 09:01:00 +00:00
if askForConfirmation() {
migrateUpdate(currpath, driver, conn)
2014-08-11 09:01:00 +00:00
}
ColorLog("[INFO] All done! Don't forget to add beego.Router(\"/%v\" ,&controllers.%vController{}) to routers/route.go\n", sname, strings.Title(sname))
}