feat: 自动迁移表结构
This commit is contained in:
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user