Skip to content

Commit 093eac4

Browse files
committed
Merge branch 'master' into xcoin
2 parents bcfe572 + 422d3d5 commit 093eac4

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

commons/dbcommons/dbmigration.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414
var sqlFs embed.FS
1515

1616
const (
17-
JChatDbVersionKey = "jchatdb_version"
18-
initVersion int64 = 20250201
17+
JChatDbVersionKey = "jchatdb_version"
1918
)
2019

2120
type CountResult struct {
@@ -27,19 +26,11 @@ func Upgrade() {
2726
var currVersion int64 = 0
2827
dao := GlobalConfDao{}
2928
conf, err := dao.FindByKey(JChatDbVersionKey)
30-
if err == nil {
29+
if err == nil && conf != nil {
3130
ver, err := utils.String2Int64(conf.ConfValue)
3231
if err == nil && ver > 0 {
3332
currVersion = ver
3433
}
35-
} else {
36-
err = dao.Create(GlobalConfDao{
37-
ConfKey: JChatDbVersionKey,
38-
ConfValue: fmt.Sprintf("%d", initVersion),
39-
})
40-
if err == nil {
41-
currVersion = initVersion
42-
}
4334
}
4435
fmt.Println("[JChatDbMigration]current version:", currVersion)
4536
sqlFiles, err := sqlFs.ReadDir("sqls")

commons/dbcommons/globalconfdao.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func (conf GlobalConfDao) FindByKey(key string) (*GlobalConfDao, error) {
3030
var item GlobalConfDao
3131
err := GetDb().Where("conf_key=?", key).Take(&item).Error
3232
if err == gorm.ErrRecordNotFound {
33-
return nil, err
33+
return nil, nil
3434
}
35-
return &item, nil
35+
return &item, err
3636
}
3737

3838
func (conf GlobalConfDao) UpdateValue(key, val string) error {

0 commit comments

Comments
 (0)