1
0
mirror of https://github.com/beego/bee.git synced 2024-12-23 01:30:50 +00:00
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) {
logger.Infof("Do you want to create a '%s' 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
logger.Infof("Do you want to create a '%s' 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
logger.Infof("Do you want to create views for this '%s' 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
logger.Infof("Do you want to create a '%s' 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
logger.Infof("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
}
logger.Successf("All done! Don't forget to add beego.Router(\"/%s\" ,&controllers.%sController{}) to routers/route.go\n", sname, strings.Title(sname))
2014-08-11 09:01:00 +00:00
}