mirror of
https://github.com/beego/bee.git
synced 2024-11-25 20:10:55 +00:00
add exit status in tpl, print output if migration binary failed to run
This commit is contained in:
parent
5900befa43
commit
c9b12183f8
20
migrate.go
20
migrate.go
@ -209,7 +209,8 @@ func buildMigrationBinary(filename string) {
|
|||||||
func runMigrationBinary(filename string) {
|
func runMigrationBinary(filename string) {
|
||||||
cmd := exec.Command("./" + filename)
|
cmd := exec.Command("./" + filename)
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
ColorLog("[ERRO] Could not run migration binary\n")
|
formatShellOutput(string(out))
|
||||||
|
ColorLog("[ERRO] Could not run migration binary: %s\n", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
} else {
|
} else {
|
||||||
formatShellOutput(string(out))
|
formatShellOutput(string(out))
|
||||||
@ -276,6 +277,7 @@ const (
|
|||||||
MIGRATION_MAIN_TPL = `package main
|
MIGRATION_MAIN_TPL = `package main
|
||||||
|
|
||||||
import(
|
import(
|
||||||
|
"os"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/astaxie/beego/migration"
|
"github.com/astaxie/beego/migration"
|
||||||
|
|
||||||
@ -290,13 +292,21 @@ func main(){
|
|||||||
task := "{{Task}}"
|
task := "{{Task}}"
|
||||||
switch task {
|
switch task {
|
||||||
case "upgrade":
|
case "upgrade":
|
||||||
migration.Upgrade({{LatestTime}})
|
if err := migration.Upgrade({{LatestTime}}); err != nil {
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
case "rollback":
|
case "rollback":
|
||||||
migration.Rollback("{{LatestName}}")
|
if err := migration.Rollback("{{LatestName}}"); err != nil {
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
case "reset":
|
case "reset":
|
||||||
migration.Reset()
|
if err := migration.Reset(); err != nil {
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
case "refresh":
|
case "refresh":
|
||||||
migration.Refresh()
|
if err := migration.Refresh(); err != nil {
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user