add AppendMigrate

This commit is contained in:
yanweidong 2025-10-05 14:57:17 +08:00
parent 820d7a5c63
commit f7d8988415
1 changed files with 8 additions and 1 deletions

View File

@ -15,7 +15,7 @@ import (
var (
// MigrateTables 存储需要在数据库初始化时自动迁移的表
MigrateTables []any
MigrateTables []any = []any{}
)
// NewDatabase 根据提供的驱动类型创建新的数据库连接
@ -133,3 +133,10 @@ func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err
return gormDb, nil
}
// AppendMigrate 调用此函数后,会在数据库初始化时自动迁移表结构
//
// - table: 需要自动迁移的表
func AppendMigrate(table any) {
MigrateTables = append(MigrateTables, table)
}