generated source format change

This commit is contained in:
ZhengYang 2014-08-07 14:39:38 +08:00
parent 2556579ad0
commit af9780691c
1 changed files with 11 additions and 13 deletions

View File

@ -25,7 +25,7 @@ import (
const ( const (
M_PATH = "migrations" M_PATH = "migrations"
M_DATE_FORMAT = "2006-01-02" M_DATE_FORMAT = "20060102_150405"
) )
// generateMigration generates migration file template for database schema update. // generateMigration generates migration file template for database schema update.
@ -46,7 +46,6 @@ func generateMigration(mname string, curpath string) {
if f, err := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666); err == nil { if f, err := os.OpenFile(fpath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666); err == nil {
defer f.Close() defer f.Close()
content := strings.Replace(MIGRATION_TPL, "{{StructName}}", camelCase(mname), -1) content := strings.Replace(MIGRATION_TPL, "{{StructName}}", camelCase(mname), -1)
content = strings.Replace(content, "{{DateFormat}}", M_DATE_FORMAT, -1)
content = strings.Replace(content, "{{CurrTime}}", today, -1) content = strings.Replace(content, "{{CurrTime}}", today, -1)
f.WriteString(content) f.WriteString(content)
// gofmt generated source code // gofmt generated source code
@ -71,27 +70,26 @@ package main
import ( import (
"time" "time"
"github.com/astaxie/beego"
"github.com/astaxie/beego/migration" "github.com/astaxie/beego/migration"
) )
func init() {
m := &{{StructName}}{}
m.Created = time.Parse("{{DateFormat}}", "{{CurrTime}}")
migration.Register(m)
}
type {{StructName}} struct { type {{StructName}} struct {
migration.Migration migration.Migration
} }
func init() {
m := &{{StructName}}{}
m.Created = "{{CurrTime}}"
migration.Register(m)
}
// Run the migrations // Run the migrations
func (m *{{StructName}}) up() { func (m *{{StructName}}) Up() {
// use m.Sql("create table ...") to make schema update // use m.Sql("CREATE TABLE ...") to make schema update
} }
// Reverse the migrations // Reverse the migrations
func (m *{{StructName}}) down() { func (m *{{StructName}}) Down() {
// use m.Sql("drop table ...") to reverse schema update // use m.Sql("DROP TABLE ...") to reverse schema update
} }
` `