Skip to content

Commit

Permalink
POC: insert to system_package2 if applicable or installable update ex…
Browse files Browse the repository at this point in the history
…ists
  • Loading branch information
psegedy committed Nov 27, 2023
1 parent 2b7cd4e commit c5f29d6
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions tasks/migration/migrate_system_package_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"

"gorm.io/gorm"
"gorm.io/gorm/clause"
)

var memoryPackageCache *evaluator.PackageCache
Expand Down Expand Up @@ -91,20 +92,24 @@ func processPartition(part string, i int) {
updateData := getUpdateData(u, as, part, i)
latestApplicable, latestInstallable := getEvraApplicability(updateData)
applicableID, installableID := getPackageIDs(u, i, latestApplicable, latestInstallable)
if applicableID != 0 && installableID != 0 {
if applicableID != 0 || installableID != 0 {
// insert ids to system_package2
err := tasks.WithTx(func(db *gorm.DB) error {
return db.Table("system_package2").
Where("installable_id IS NULL AND applicable_id IS NULL").
Save(models.SystemPackage{
RhAccountID: as.RhAccountID,
SystemID: as.SystemID,
PackageID: u.PackageID,
NameID: u.NameID,
InstallableID: &installableID,
ApplicableID: &applicableID,
}).Error
})
toInsert := models.SystemPackage{
RhAccountID: as.RhAccountID,
SystemID: as.SystemID,
PackageID: u.PackageID,
NameID: u.NameID,
}
if installableID != 0 {
toInsert.InstallableID = &installableID
}
if applicableID != 0 {
toInsert.ApplicableID = &applicableID
}
err := tx.Clauses(clause.OnConflict{DoNothing: true}).
Table("system_package2").
Where("installable_id IS NULL AND applicable_id IS NULL").
Save(toInsert).Error
if err != nil {
utils.LogWarn("#", i, "Failed to update system_package2")
}
Expand Down

0 comments on commit c5f29d6

Please sign in to comment.