mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-20 02:37:59 +08:00
修改MySQL无法修改数据库的BUG
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/lifei6671/godoc/conf"
|
"github.com/lifei6671/godoc/conf"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
//系统升级.
|
//系统升级.
|
||||||
@@ -32,13 +33,23 @@ func Update() {
|
|||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
sql := string(b)
|
sqls := string(b)
|
||||||
|
|
||||||
_,err = o.Raw(sql).Exec()
|
if sqls != "" {
|
||||||
if err != nil {
|
items := strings.Split(sqls,"\r\n")
|
||||||
panic("SITE_NAME => " + err.Error())
|
for _,sql := range items {
|
||||||
os.Exit(1)
|
if sql != "" {
|
||||||
|
_,err = o.Raw(sql).Exec()
|
||||||
|
|
||||||
|
if err != nil && err != orm.ErrNoRows{
|
||||||
|
panic("SITE_NAME => " + err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("update successed.")
|
fmt.Println("update successed.")
|
||||||
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@@ -82,18 +93,19 @@ func CheckUpdate() {
|
|||||||
|
|
||||||
//MySQL 数据库更新表结构.
|
//MySQL 数据库更新表结构.
|
||||||
func mysqlUpdate() {
|
func mysqlUpdate() {
|
||||||
sql := `
|
db_name := beego.AppConfig.String("db_database")
|
||||||
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema=CurrentDatabase AND table_name = 'md_members' AND column_name = 'auth_method') THEN
|
|
||||||
ALTER TABLE md_members ADD auth_method VARCHAR(50) DEFAULT 'local' NULL;
|
|
||||||
END IF; `
|
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
|
||||||
_,err := o.Raw(sql).Exec()
|
var total_count int
|
||||||
|
|
||||||
|
err := o.Raw("SELECT COUNT(*) AS total_count FROM information_schema.columns WHERE table_schema= ? AND table_name = 'md_members' AND column_name = 'auth_method'",db_name).QueryRow(&total_count)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("error : 6001 => %s",err.Error()))
|
panic(fmt.Sprintf("error : 6001 => %s",err.Error()))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
_,err = o.Raw("ALTER TABLE md_members ADD auth_method VARCHAR(50) DEFAULT 'local' NULL").Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
//sqlite 数据库更新表结构.
|
//sqlite 数据库更新表结构.
|
||||||
|
Reference in New Issue
Block a user