feat: 自动迁移表结构

This commit is contained in:
Blizzard
2025-04-26 11:58:41 +08:00
parent 248ed10c62
commit 5e41df7dc2
7 changed files with 77 additions and 9 deletions
+16
View File
@@ -1,6 +1,8 @@
package main
import (
"context"
"database/sql"
"go.uber.org/zap"
"sundynix-go/core"
"sundynix-go/global"
@@ -18,5 +20,19 @@ func main() {
global.DB = initialize.Gorm()
//redis连接
initialize.Redis()
global.Redis.Set(context.Background(), "test", 0, -1)
//迁移数据库
if global.DB != nil {
initialize.MigrateTable() // 迁移数据库结构
db, _ := global.DB.DB()
defer func(db *sql.DB) {
err := db.Close()
if err != nil {
global.Logger.Error("db close failed", zap.Error(err))
}
}(db)
}
}