daShangDao_psiServer/database/product_book.go

24 lines
725 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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])
}