mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
db
This commit is contained in:
parent
6a7a76dce3
commit
41dd808c9a
@ -33,23 +33,22 @@ func initMysqlDB() {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||||
|
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||||
|
db, err := gorm.Open("mysql", dsn)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError("0", "Open failed ", err.Error(), dsn)
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
//Check the database and table during initialization
|
//Check the database and table during initialization
|
||||||
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
|
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
|
||||||
err := db.Exec(sql).Error
|
err = db.Exec(sql).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "Exec failed ", err.Error(), sql)
|
log.NewError("0", "Exec failed ", err.Error(), sql)
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
|
||||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
|
||||||
db, err = gorm.Open("mysql", dsn)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError("0", "Open failed ", err.Error(), dsn)
|
|
||||||
panic(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
log.NewInfo("open db ok ", dsn)
|
log.NewInfo("open db ok ", dsn)
|
||||||
db.AutoMigrate(&Friend{},
|
db.AutoMigrate(&Friend{},
|
||||||
&FriendRequest{},
|
&FriendRequest{},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user