answer/internal/cli/install_check.go

57 lines
1.3 KiB
Go
Raw Normal View History

2022-10-12 11:49:28 +08:00
package cli
import (
2022-11-10 12:13:42 +08:00
"fmt"
"github.com/answerdev/answer/internal/base/data"
2022-11-03 20:09:04 +08:00
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/pkg/dir"
2022-10-12 11:49:28 +08:00
)
2022-10-12 20:20:26 +08:00
func CheckConfigFile(configPath string) bool {
return dir.CheckFileExist(configPath)
2022-10-12 11:49:28 +08:00
}
func CheckUploadDir() bool {
return dir.CheckDirExist(UploadFilePath)
2022-10-12 11:49:28 +08:00
}
// CheckDBConnection check database whether the connection is normal
func CheckDBConnection(dataConf *data.Database) bool {
2022-10-12 11:49:28 +08:00
db, err := data.NewDB(false, dataConf)
if err != nil {
2022-11-10 12:13:42 +08:00
fmt.Printf("connection database failed: %s\n", err)
2022-10-12 11:49:28 +08:00
return false
}
if err = db.Ping(); err != nil {
2022-11-10 12:13:42 +08:00
fmt.Printf("connection ping database failed: %s\n", err)
2022-10-12 11:49:28 +08:00
return false
}
return true
}
// CheckDBTableExist check database whether the table is already exists
func CheckDBTableExist(dataConf *data.Database) bool {
db, err := data.NewDB(false, dataConf)
if err != nil {
fmt.Printf("connection database failed: %s\n", err)
return false
}
if err = db.Ping(); err != nil {
fmt.Printf("connection ping database failed: %s\n", err)
return false
2022-11-03 20:09:04 +08:00
}
exist, err := db.IsTableExist(&entity.Version{})
if err != nil {
2022-11-10 12:13:42 +08:00
fmt.Printf("check table exist failed: %s\n", err)
2022-11-03 20:09:04 +08:00
return false
}
if !exist {
2022-11-10 12:13:42 +08:00
fmt.Printf("check table not exist\n")
2022-11-03 20:09:04 +08:00
return false
}
2022-10-12 11:49:28 +08:00
return true
}