You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/db/relation/file_model.go

51 lines
1.5 KiB

2 years ago
package relation
3 years ago
import (
2 years ago
"gorm.io/gorm"
3 years ago
"time"
)
2 years ago
var AppDB *gorm.DB
2 years ago
type AppVersion struct {
Version string `gorm:"column:version;size:64" json:"version"`
Type int `gorm:"column:type;primary_key" json:"type"`
UpdateTime int `gorm:"column:update_time" json:"update_time"`
ForceUpdate bool `gorm:"column:force_update" json:"force_update"`
FileName string `gorm:"column:file_name" json:"file_name"`
YamlName string `gorm:"column:yaml_name" json:"yaml_name"`
UpdateLog string `gorm:"column:update_log" json:"update_log"`
}
func (AppVersion) TableName() string {
return "app_version"
}
3 years ago
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
3 years ago
updateTime := int(time.Now().Unix())
app := AppVersion{
3 years ago
Version: version,
Type: appType,
UpdateTime: updateTime,
FileName: fileName,
YamlName: yamlName,
ForceUpdate: forceUpdate,
3 years ago
UpdateLog: updateLog,
3 years ago
}
2 years ago
result := AppDB.Model(AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
3 years ago
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
3 years ago
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
2 years ago
err := AppDB.Create(&app).Error
3 years ago
return err
}
return nil
}
func GetNewestVersion(appType int) (*AppVersion, error) {
app := AppVersion{}
2 years ago
return &app, AppDB.Model(AppVersion{}).First(&app, appType).Error
3 years ago
}