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
|
|
|
|
2016-07-31 21:30:35 +00:00
|
|
|
func generateScaffold(sname, fields, currpath, driver, conn string) {
|
2016-11-13 14:14:48 +00:00
|
|
|
logger.Infof("Do you want to create a '%s' model? [Yes|No] ", sname)
|
2016-07-31 21:30:35 +00:00
|
|
|
|
|
|
|
// Generate the model
|
2014-08-11 09:01:00 +00:00
|
|
|
if askForConfirmation() {
|
2016-07-31 21:30:35 +00:00
|
|
|
generateModel(sname, fields, currpath)
|
2014-08-11 09:01:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 21:30:35 +00:00
|
|
|
// Generate the controller
|
2016-11-13 14:14:48 +00:00
|
|
|
logger.Infof("Do you want to create a '%s' controller? [Yes|No] ", sname)
|
2014-08-11 09:01:00 +00:00
|
|
|
if askForConfirmation() {
|
2016-07-31 21:30:35 +00:00
|
|
|
generateController(sname, currpath)
|
2014-08-11 09:01:00 +00:00
|
|
|
}
|
2016-07-31 21:30:35 +00:00
|
|
|
|
|
|
|
// Generate the views
|
2016-11-13 14:14:48 +00:00
|
|
|
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() {
|
2016-07-31 21:30:35 +00:00
|
|
|
generateView(sname, currpath)
|
2014-08-11 09:01:00 +00:00
|
|
|
}
|
2016-07-31 21:30:35 +00:00
|
|
|
|
|
|
|
// Generate a migration
|
2016-11-13 14:14:48 +00:00
|
|
|
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
|
|
|
}
|
2016-07-31 21:30:35 +00:00
|
|
|
generateMigration(sname, upsql, downsql, currpath)
|
2014-08-11 09:01:00 +00:00
|
|
|
}
|
2016-07-31 21:30:35 +00:00
|
|
|
|
|
|
|
// Run the migration
|
2016-11-13 14:14:48 +00:00
|
|
|
logger.Infof("Do you want to migrate the database? [Yes|No] ")
|
2014-08-11 09:01:00 +00:00
|
|
|
if askForConfirmation() {
|
2016-07-31 21:30:35 +00:00
|
|
|
migrateUpdate(currpath, driver, conn)
|
2014-08-11 09:01:00 +00:00
|
|
|
}
|
2016-11-13 14:14:48 +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
|
|
|
}
|