mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 08:28:52 +00:00
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:
parent
fdc184fe58
commit
c42a732ef7
1 changed files with 4 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue