Skip to content

Commit 91cd572

Browse files
committed
fix version update
1 parent c42aa28 commit 91cd572

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

node-registrar/pkg/db/version.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package db
22

33
import (
44
"errors"
5-
"reflect"
65

76
"gorm.io/gorm"
87
)
98

9+
const zos4Key = "zos_4"
10+
1011
func (db *Database) SetZOSVersion(version ZosVersion) error {
1112
var current ZosVersion
1213
result := db.gormDB.Where(ZosVersion{Key: ZOS4VersionKey}).Attrs(ZosVersion{Version: version.Version}).FirstOrCreate(&current)
@@ -16,18 +17,25 @@ func (db *Database) SetZOSVersion(version ZosVersion) error {
1617
}
1718

1819
if result.RowsAffected == 0 {
19-
if reflect.DeepEqual(current, version) {
20+
update := map[string]any{}
21+
if current.Version != version.Version {
22+
update["version"] = version.Version
23+
}
24+
if current.SafeToUpgrade != version.SafeToUpgrade {
25+
update["safe_to_upgrade"] = version.SafeToUpgrade
26+
}
27+
if len(update) == 0 {
2028
return ErrVersionAlreadySet
2129
}
2230
return db.gormDB.Model(&current).
23-
Select("version").
31+
Where("key = ?", zos4Key).
2432
Updates(version).Error
2533
}
2634
return nil
2735
}
2836

2937
func (db *Database) GetZOSVersion() (version ZosVersion, err error) {
30-
if err := db.gormDB.Where("key = ?", "zos_4").First(&version).Error; err != nil {
38+
if err := db.gormDB.Where("key = ?", zos4Key).First(&version).Error; err != nil {
3139
if errors.Is(err, gorm.ErrRecordNotFound) {
3240
return version, ErrRecordNotFound
3341
}

0 commit comments

Comments
 (0)