feat:完善信息

This commit is contained in:
henry
2021-10-15 15:06:02 +08:00
parent af8691e943
commit ae9fb8ea0f
86 changed files with 215 additions and 216 deletions

View File

@ -0,0 +1,44 @@
package tenant
import (
model2 "SciencesServer/app/common/model"
"SciencesServer/config"
"fmt"
"gorm.io/gorm"
)
type Sub struct{}
type SubHandle func() *Sub
// database 数据表
func (c *Sub) database(key string) string {
return model2.SubDatabase + "_" + key
}
// sync 同步数据
func (c *Sub) sync(tx *gorm.DB, database string) error {
// TODO生成租户对应数据库并生成对应数据表
err := tx.Exec(fmt.Sprintf("CREATE DATABASE %s;", database)).Error
if err != nil {
return err
}
// 使用生成后的数据库
if err = tx.Exec(fmt.Sprintf("use %s;", database)).Error; err != nil {
return err
}
iModels := []model2.IModel{}
for _, v := range iModels {
if err = tx.Migrator().CreateTable(v); err != nil {
return err
}
}
// 重新使用默认的数据库
tx.Exec(fmt.Sprintf("use %s;", config.SettingInfo.Engine.Mysql.DBName))
return nil
}