This commit is contained in:
wangchuxiao
2022-05-10 10:44:43 +08:00
parent 97e5d9f610
commit 00265a7e8e
27 changed files with 369 additions and 187 deletions
+1
View File
@@ -63,6 +63,7 @@ type config struct {
}
Minio struct {
Bucket string `yaml:"bucket"`
AppBucket string `yaml:"appBucket"`
Location string `yaml:"location"`
Endpoint string `yaml:"endpoint"`
AccessKeyID string `yaml:"accessKeyID"`
+11
View File
@@ -272,3 +272,14 @@ type DepartmentMember struct {
func (DepartmentMember) TableName() string {
return "department_members"
}
type AppVersion struct {
Version string `gorm:"column:user_id;size:64"`
Type int `gorm:"column:user_id;primary_key"`
UpdateTime int `gorm:"column:update_time"`
ForceUpdate bool `gorm:"column:force_update"`
}
func (AppVersion) TableName() string {
return "app_version"
}
+4 -1
View File
@@ -119,7 +119,10 @@ func initMysqlDB() {
fmt.Println("CreateTable DepartmentMember")
db.CreateTable(&DepartmentMember{})
}
if !db.HasTable(&AppVersion{}) {
fmt.Println("CreateTable DepartmentMember")
db.CreateTable(&AppVersion{})
}
return
}
@@ -0,0 +1,38 @@
package im_mysql_model
import (
"Open_IM/pkg/common/db"
"time"
)
func UpdateAppVersion(appType int, version string, forceUpdate bool) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
app := db.AppVersion{
Version: version,
Type: appType,
UpdateTime: int(time.Now().Unix()),
ForceUpdate: forceUpdate,
}
result := dbConn.Model(db.AppVersion{}).Where("app_type = ?", appType).Updates(&app)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
err := dbConn.Create(&app).Error
return err
}
return nil
}
func GetNewestVersion(appType int) (*db.AppVersion, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
dbConn.LogMode(true)
app := db.AppVersion{}
return &app, dbConn.Model(db.AppVersion{}).First(&app, appType).Error
}