package dao

import (
	"fmt"
	"gorm.io/gorm"
	"iot_manager_service/util/common"
)

var Db *gorm.DB

func InitDB(db *gorm.DB) {
	Db = db
	models := []common.TableModelAuto{
		{&Library{}, "素材表"},
		{&Program{}, "节目表"},
		{&ProgramRelation{}, "节目排期表"},
		{&PublishLibraries{}, "已发布节目单库"},
	}
	for _, val := range models {
		//fmt.Println(val.Model)
		err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
		if err != nil {
			panic(fmt.Sprintf("AutoMigrate err : %v", err))
		}
	}
}
