|
@@ -42,17 +42,19 @@ func InitDB() (err error) {
|
|
|
var db *gorm.DB
|
|
var db *gorm.DB
|
|
|
if os.Getenv("SQL_DSN") != "" {
|
|
if os.Getenv("SQL_DSN") != "" {
|
|
|
// Use MySQL
|
|
// Use MySQL
|
|
|
|
|
+ common.SysLog("using MySQL as database")
|
|
|
db, err = gorm.Open(mysql.Open(os.Getenv("SQL_DSN")), &gorm.Config{
|
|
db, err = gorm.Open(mysql.Open(os.Getenv("SQL_DSN")), &gorm.Config{
|
|
|
PrepareStmt: true, // precompile SQL
|
|
PrepareStmt: true, // precompile SQL
|
|
|
})
|
|
})
|
|
|
} else {
|
|
} else {
|
|
|
// Use SQLite
|
|
// Use SQLite
|
|
|
|
|
+ common.SysLog("SQL_DSN not set, using SQLite as database")
|
|
|
common.UsingSQLite = true
|
|
common.UsingSQLite = true
|
|
|
db, err = gorm.Open(sqlite.Open(common.SQLitePath), &gorm.Config{
|
|
db, err = gorm.Open(sqlite.Open(common.SQLitePath), &gorm.Config{
|
|
|
PrepareStmt: true, // precompile SQL
|
|
PrepareStmt: true, // precompile SQL
|
|
|
})
|
|
})
|
|
|
- common.SysLog("SQL_DSN not set, using SQLite as database")
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ common.SysLog("Database connected")
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
DB = db
|
|
DB = db
|
|
|
if !common.IsMasterNode {
|
|
if !common.IsMasterNode {
|
|
@@ -86,6 +88,7 @@ func InitDB() (err error) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
+ common.SysLog("Database migrated")
|
|
|
err = createRootAccountIfNeed()
|
|
err = createRootAccountIfNeed()
|
|
|
return err
|
|
return err
|
|
|
} else {
|
|
} else {
|