common.go 551 B

1234567891011121314151617181920212223242526
  1. package dao
  2. import (
  3. "fmt"
  4. "gorm.io/gorm"
  5. "iot_manager_service/util/common"
  6. )
  7. var Db *gorm.DB
  8. func InitDB(db *gorm.DB) {
  9. Db = db
  10. models := []common.TableModelAuto{
  11. {&Library{}, "素材表"},
  12. {&Program{}, "节目表"},
  13. {&ProgramRelation{}, "节目排期表"},
  14. {&PublishLibraries{}, "已发布节目单库"},
  15. }
  16. for _, val := range models {
  17. //fmt.Println(val.Model)
  18. err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
  19. if err != nil {
  20. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  21. }
  22. }
  23. }