engineerper 1 yıl önce
ebeveyn
işleme
bde131c69f
2 değiştirilmiş dosya ile 36 ekleme ve 4 silme
  1. 2 0
      global/global.go
  2. 34 4
      initialize/gorm.go

+ 2 - 0
global/global.go

@@ -3,6 +3,7 @@ package global
 import (
 	"github.com/redis/go-redis/v9"
 	"github.com/songzhibin97/gkit/cache/local_cache"
+	"go.uber.org/zap"
 	"golang.org/x/sync/singleflight"
 	"gorm.io/gorm"
 	"lc-fangdaosha/config"
@@ -13,6 +14,7 @@ var (
 	Db                      *gorm.DB
 	GVA_REDIS               *redis.Client
 	BlackCache              local_cache.Cache
+	GVA_LOG                 *zap.Logger
 	Config                  = config.Config
 	GVA_Concurrency_Control = &singleflight.Group{}
 )

+ 34 - 4
initialize/gorm.go

@@ -2,16 +2,17 @@ package initialize
 
 import (
 	"fmt"
+	"github.com/flipped-aurora/gin-vue-admin/server/model/system"
+	"go.uber.org/zap"
 	"gorm.io/driver/mysql"
+	"gorm.io/gorm"
 	"gorm.io/gorm/logger"
 	"gorm.io/gorm/schema"
+	"lc-fangdaosha/global"
+	"lc-fangdaosha/model/app"
 	"log"
 	"os"
 	"time"
-
-	"lc-fangdaosha/global"
-
-	"gorm.io/gorm"
 )
 
 func Gorm() *gorm.DB {
@@ -36,6 +37,35 @@ func Gorm() *gorm.DB {
 		return db
 	}
 }
+func RegisterTables() {
+	db := global.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{},
+		//example.ExaFile{},
+		//example.ExaCustomer{},
+		//example.ExaFileChunk{},
+		//example.ExaFileUploadAndDownload{},
+		app.Camera{}, app.Picture{}, app.PictureData{}, app.Gateway{}, app.Event{},
+	)
+	if err != nil {
+		global.GVA_LOG.Error("register table failed", zap.Error(err))
+		os.Exit(0)
+	}
+	global.GVA_LOG.Info("register table success")
+}
 
 type DBBASE interface {
 	GetLogMode() string