beego hook change the path & fix the migration bug
Showing
2 changed files
with
8 additions
and
6 deletions
| ... | @@ -388,6 +388,9 @@ func initBeforeHttpRun() { | ... | @@ -388,6 +388,9 @@ func initBeforeHttpRun() { |
| 388 | Get("/docs", serverDocs) | 388 | Get("/docs", serverDocs) |
| 389 | Get("/docs/*", serverDocs) | 389 | Get("/docs/*", serverDocs) |
| 390 | } | 390 | } |
| 391 | |||
| 392 | //init mime | ||
| 393 | AddAPPStartHook(initMime) | ||
| 391 | } | 394 | } |
| 392 | 395 | ||
| 393 | // this function is for test package init | 396 | // this function is for test package init |
| ... | @@ -406,6 +409,4 @@ func TestBeegoInit(apppath string) { | ... | @@ -406,6 +409,4 @@ func TestBeegoInit(apppath string) { |
| 406 | 409 | ||
| 407 | func init() { | 410 | func init() { |
| 408 | hooks = make([]hookfunc, 0) | 411 | hooks = make([]hookfunc, 0) |
| 409 | //init mime | ||
| 410 | AddAPPStartHook(initMime) | ||
| 411 | } | 412 | } | ... | ... |
| ... | @@ -23,6 +23,7 @@ package migration | ... | @@ -23,6 +23,7 @@ package migration |
| 23 | import ( | 23 | import ( |
| 24 | "errors" | 24 | "errors" |
| 25 | "sort" | 25 | "sort" |
| 26 | "strconv" | ||
| 26 | "strings" | 27 | "strings" |
| 27 | "time" | 28 | "time" |
| 28 | 29 | ||
| ... | @@ -82,11 +83,11 @@ func (m *Migration) Exec(name, status string) error { | ... | @@ -82,11 +83,11 @@ func (m *Migration) Exec(name, status string) error { |
| 82 | return m.addOrUpdateRecord(name, status) | 83 | return m.addOrUpdateRecord(name, status) |
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | func (m *Migration) addOrUpdateRecord(status, name string) error { | 86 | func (m *Migration) addOrUpdateRecord(name, status string) error { |
| 86 | o := orm.NewOrm() | 87 | o := orm.NewOrm() |
| 87 | if status == "down" { | 88 | if status == "down" { |
| 88 | status = "rollback" | 89 | status = "rollback" |
| 89 | p, err := o.Raw("update migrations set status = ?,rollback_statements = ? where name = ?").Prepare() | 90 | p, err := o.Raw("update migrations set status = ?, rollback_statements = ? where name = ?").Prepare() |
| 90 | if err != nil { | 91 | if err != nil { |
| 91 | return nil | 92 | return nil |
| 92 | } | 93 | } |
| ... | @@ -94,11 +95,11 @@ func (m *Migration) addOrUpdateRecord(status, name string) error { | ... | @@ -94,11 +95,11 @@ func (m *Migration) addOrUpdateRecord(status, name string) error { |
| 94 | return err | 95 | return err |
| 95 | } else { | 96 | } else { |
| 96 | status = "update" | 97 | status = "update" |
| 97 | p, err := o.Raw("insert into migrations(`name`,`created_at`,`statements`,`status`) values(?,?,?,?)").Prepare() | 98 | p, err := o.Raw("insert into migrations(`name`, `created_at`, `statements`, `status`) values(?,?,?,?)").Prepare() |
| 98 | if err != nil { | 99 | if err != nil { |
| 99 | return err | 100 | return err |
| 100 | } | 101 | } |
| 101 | _, err = p.Exec(name, m.GetCreated(), strings.Join(m.sqls, "; "), status) | 102 | _, err = p.Exec(name, strconv.FormatInt(m.GetCreated(), 10), strings.Join(m.sqls, "; "), status) |
| 102 | return err | 103 | return err |
| 103 | } | 104 | } |
| 104 | } | 105 | } | ... | ... |
-
Please register or sign in to post a comment