2023-11-02 04:34:46 +08:00
|
|
|
package initialize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"miniapp/model/app"
|
|
|
|
"miniapp/model/common"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"miniapp/global"
|
|
|
|
"miniapp/model/example"
|
|
|
|
"miniapp/model/system"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Gorm 初始化数据库并产生数据库全局变量
|
|
|
|
// Author SliverHorn
|
|
|
|
func Gorm() *gorm.DB {
|
|
|
|
switch global.GVA_CONFIG.System.DbType {
|
|
|
|
case "mysql":
|
|
|
|
return GormMysql()
|
|
|
|
case "pgsql":
|
|
|
|
return GormPgSql()
|
|
|
|
case "oracle":
|
|
|
|
return GormOracle()
|
|
|
|
case "mssql":
|
|
|
|
return GormMssql()
|
|
|
|
case "sqlite":
|
|
|
|
return GormSqlite()
|
|
|
|
default:
|
|
|
|
return GormMysql()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterTables 注册数据库表专用
|
|
|
|
// Author SliverHorn
|
|
|
|
func RegisterTables() {
|
|
|
|
db := global.GVA_DB
|
|
|
|
err := db.AutoMigrate(
|
|
|
|
// 系统模块表
|
|
|
|
system.SysApi{},
|
|
|
|
system.SysUser{},
|
|
|
|
system.SysBaseMenu{},
|
|
|
|
system.JwtBlacklist{},
|
|
|
|
system.SysAuthority{},
|
|
|
|
system.SysDictionary{},
|
|
|
|
system.SysOperationRecord{},
|
|
|
|
system.SysAutoCodeHistory{},
|
|
|
|
system.SysDictionaryDetail{},
|
|
|
|
system.SysBaseMenuParameter{},
|
|
|
|
system.SysBaseMenuBtn{},
|
|
|
|
system.SysAuthorityBtn{},
|
|
|
|
system.SysAutoCode{},
|
|
|
|
system.SysChatGptOption{},
|
2023-11-10 09:30:29 +08:00
|
|
|
system.Aikefu{},
|
2023-11-02 04:34:46 +08:00
|
|
|
|
|
|
|
example.ExaFile{},
|
|
|
|
example.ExaCustomer{},
|
|
|
|
example.ExaFileChunk{},
|
|
|
|
example.ExaFileUploadAndDownload{},
|
|
|
|
|
|
|
|
app.User{},
|
|
|
|
app.OAuth2Client{},
|
|
|
|
app.Favorite{},
|
|
|
|
app.Vision{},
|
|
|
|
|
|
|
|
common.Hospital{},
|
|
|
|
common.Notes{},
|
|
|
|
common.Todos{},
|
|
|
|
common.Article{},
|
|
|
|
common.Banner{},
|
|
|
|
common.UserTodo{},
|
2024-01-11 16:03:51 +08:00
|
|
|
common.Poster{},
|
2023-11-02 04:34:46 +08:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
global.GVA_LOG.Error("register table failed", zap.Error(err))
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
global.GVA_LOG.Info("register table success")
|
|
|
|
}
|