2 Star 2 Fork 4

联犀/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
modelMigrate.go 3.92 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-11 10:52 . feat: 更新mod
package relationDB
import (
"context"
"database/sql"
"gitee.com/unitedrhino/share/conf"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/stores"
"gorm.io/gorm/clause"
)
func Migrate(c conf.Database) error {
if c.IsInitTable == false {
return nil
}
db := stores.GetCommonConn(context.TODO())
var needInitColumn bool
if !db.Migrator().HasTable(&SysUserInfo{}) {
//需要初始化表
needInitColumn = true
}
err := db.AutoMigrate(
&SysUserMessage{},
&SysMessageInfo{},
&SysNotifyConfig{},
&SysNotifyTemplate{},
&SysNotifyConfigTemplate{},
&SysDictInfo{},
&SysDictDetail{},
&SysSlotInfo{},
&SysUserInfo{},
&SysRoleInfo{},
&SysRoleMenu{},
&SysRoleAccess{},
&SysTenantAgreement{},
&SysRoleModule{},
&SysModuleMenu{},
&SysLoginLog{},
&SysOperLog{},
&SysApiInfo{},
&SysAccessInfo{},
&SysAreaInfo{},
&SysProjectInfo{},
&SysOpsWorkOrder{},
&SysOpsFeedback{},
&SysDataArea{},
&SysDataProject{},
&SysAppInfo{},
&SysRoleApp{},
&SysUserRole{},
&SysTenantInfo{},
&SysTenantOpenWebhook{},
&SysDataOpenAccess{},
&SysTenantApp{},
&SysTenantAccess{},
&SysTenantConfig{},
&SysModuleInfo{},
&SysAppModule{},
&SysTenantAppMenu{},
&SysTenantAppModule{},
&SysUserAreaApply{},
&SysUserProfile{},
&SysNotifyChannel{},
&SysProjectProfile{},
&SysAreaProfile{},
)
if err != nil {
return err
}
//{
// db := stores.GetCommonConn(context.TODO()).Clauses(clause.OnConflict{DoNothing: true})
// if err := db.CreateInBatches(&MigrateDictDetailAdcode, 100).Error; err != nil {
// return err
// }
// if err := db.CreateInBatches(&MigrateDictInfo, 100).Error; err != nil {
// return err
// }
//}
if needInitColumn {
return migrateTableColumn()
}
return err
}
func migrateTableColumn() error {
db := stores.GetCommonConn(context.TODO()).Clauses(clause.OnConflict{DoNothing: true})
if err := db.CreateInBatches(&MigrateUserInfo, 100).Error; err != nil {
return err
}
if err := db.CreateInBatches(&MigrateRoleInfo, 100).Error; err != nil {
return err
}
if err := db.CreateInBatches(&MigrateUserRole, 100).Error; err != nil {
return err
}
if err := db.CreateInBatches(&MigrateTenantInfo, 100).Error; err != nil {
return err
}
if err := db.CreateInBatches(&MigrateProjectInfo, 100).Error; err != nil {
return err
}
if err := db.CreateInBatches(&MigrateTenantConfig, 100).Error; err != nil {
return err
}
if err := db.CreateInBatches(&MigrateDictDetailAdcode, 100).Error; err != nil {
return err
}
return nil
}
const (
adminUserID = 1740358057038188544
defaultProjectID = 1786838173980422144
)
// 子应用管理员可以配置自己子应用的角色
var (
MigrateTenantAppMenu = []SysTenantAppMenu{}
MigrateTenantConfig = []SysTenantConfig{
{TenantCode: def.TenantCodeDefault, RegisterRoleID: 2},
}
MigrateProjectInfo = []SysProjectInfo{{TenantCode: def.TenantCodeDefault, AdminUserID: adminUserID, ProjectID: defaultProjectID, ProjectName: "默认项目"}}
MigrateTenantInfo = []SysTenantInfo{{Code: def.TenantCodeDefault, Name: "默认租户", AdminUserID: adminUserID, DefaultProjectID: defaultProjectID}}
MigrateUserInfo = []SysUserInfo{
{TenantCode: def.TenantCodeDefault, UserID: adminUserID, UserName: sql.NullString{String: "administrator", Valid: true}, Password: "4f0fded4a38abe7a3ea32f898bb82298", Role: 1, NickName: "联犀管理员", IsAllData: def.True},
}
MigrateUserRole = []SysUserRole{
{TenantCode: def.TenantCodeDefault, UserID: adminUserID, RoleID: 1},
{TenantCode: def.TenantCodeDefault, UserID: adminUserID, RoleID: 2},
{TenantCode: def.TenantCodeDefault, UserID: adminUserID, RoleID: 3},
}
MigrateRoleInfo = []SysRoleInfo{
{ID: 1, TenantCode: def.TenantCodeDefault, Name: "管理员", Code: def.RoleCodeAdmin},
{ID: 2, TenantCode: def.TenantCodeDefault, Name: "普通用户", Code: def.RoleCodeClient, Desc: "C端用户"},
{ID: 3, TenantCode: def.TenantCodeDefault, Name: "超级管理员", Code: def.RoleCodeSupper}}
)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/unitedrhino/core.git
git@gitee.com:unitedrhino/core.git
unitedrhino
core
core
v0.2.3

搜索帮助