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