24 lines
725 B
Go
24 lines
725 B
Go
package database
|
||
|
||
import (
|
||
"log"
|
||
"psi/models"
|
||
)
|
||
|
||
// InitProductBookTables 初始化商品书籍分表(product_book_00 ~ product_book_99)
|
||
func InitProductBookTables() {
|
||
migrator := DB.Migrator()
|
||
tableNames := models.ProductBookAllTableNames()
|
||
|
||
for _, tableName := range tableNames {
|
||
if !migrator.HasTable(tableName) {
|
||
err := DB.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品书籍分表'").
|
||
Table(tableName).AutoMigrate(&models.ProductBook{})
|
||
if err != nil {
|
||
log.Fatalf("%s 表迁移失败: %v", tableName, err)
|
||
}
|
||
}
|
||
}
|
||
log.Printf("商品书籍分表初始化完成,共 %d 张表(%s ~ %s)", len(tableNames), tableNames[0], tableNames[len(tableNames)-1])
|
||
}
|