mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-23 23:32:15 +08:00
25 lines
596 B
Go
25 lines
596 B
Go
package global
|
|
|
|
import (
|
|
"gofiber.study.skcks.cn/common/logger"
|
|
"gofiber.study.skcks.cn/model/user/models"
|
|
"xorm.io/xorm"
|
|
"xorm.io/xorm/names"
|
|
)
|
|
|
|
var DataSources *xorm.EngineGroup
|
|
|
|
func SyncModelToDataSource() {
|
|
modelArr := []interface{ names.TableName }{&models.User{}}
|
|
|
|
logger.Log.Infof("[*] 同步数据库/表结构")
|
|
for _, model := range modelArr {
|
|
err := DataSources.Sync(model)
|
|
logger.Log.Infof("[√] 同步 %s 表 数据结构 成功", model.TableName())
|
|
|
|
if err != nil {
|
|
logger.Log.Fatalf("[x] 同步 %s 表 数据结构时出错: %s", model.TableName(), err)
|
|
}
|
|
}
|
|
}
|