This commit is contained in:
yanweidong 2025-10-05 15:00:07 +08:00
parent 3d6871138a
commit 404957f16a
1 changed files with 5 additions and 1 deletions

View File

@ -15,7 +15,7 @@ import (
var (
// MigrateTables 存储需要在数据库初始化时自动迁移的表
MigrateTables []any = make([]any, 0)
MigrateTables []any
)
// NewDatabase 根据提供的驱动类型创建新的数据库连接
@ -25,6 +25,7 @@ var (
// options: 数据库连接选项
// 返回: GORM数据库实例
func NewDatabase(driver string, dsn []string, options *types.SqlOptions) (db *gorm.DB, err error) {
MigrateTables = make([]any, 0)
driver = strings.ToLower(driver)
switch driver {
case "mysql":
@ -138,5 +139,8 @@ func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err
//
// - table: 需要自动迁移的表
func AppendMigrate(table any) {
if MigrateTables == nil {
MigrateTables = make([]any, 0)
}
MigrateTables = append(MigrateTables, table)
}