Unbatching checksum migration (#34586)

**Related issue:** https://github.com/fleetdm/fleet/issues/34559
PR for 4.75.1: https://github.com/fleetdm/fleet/pull/34485

needs to be added in main to be consistent.
This commit is contained in:
Konstantin Sykulev 2025-10-21 11:21:33 -05:00 committed by GitHub
parent fdc184fe58
commit c42a732ef7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,30 +10,7 @@ func init() {
}
func Up_20251015103505(tx *sql.Tx) error {
var minID, maxID sql.NullInt64
err := tx.QueryRow(`
SELECT MIN(id), MAX(id)
FROM software
WHERE source = 'apps'
AND bundle_identifier IS NOT NULL
AND bundle_identifier != ''
`).Scan(&minID, &maxID)
if err != nil {
return fmt.Errorf("getting ID range: %w", err)
}
if !minID.Valid || !maxID.Valid {
return nil
}
const batchSize = 10000
for startID := minID.Int64; startID <= maxID.Int64; startID += batchSize {
endID := startID + batchSize - 1
if endID > maxID.Int64 {
endID = maxID.Int64
}
softwareStmt := `
softwareStmt := `
UPDATE software SET
checksum = UNHEX(
MD5(
@ -54,12 +31,10 @@ func Up_20251015103505(tx *sql.Tx) error {
WHERE source = 'apps'
AND bundle_identifier IS NOT NULL
AND bundle_identifier != ''
AND id >= ? AND id <= ?
`
_, err = tx.Exec(softwareStmt, startID, endID)
if err != nil {
return fmt.Errorf("updating software checksums (batch %d-%d): %w", startID, endID, err)
}
_, err := tx.Exec(softwareStmt)
if err != nil {
return fmt.Errorf("updating software checksums %w", err)
}
return nil