migrate build plans in batches
concourse/concourse#1339
@@ -2,6 +2,7 @@ package migrations
import (
"encoding/json"
+ "fmt"
"github.com/concourse/atc/db/migration"
internal "github.com/concourse/atc/db/migrations/internal/163"
@@ -24,11 +25,16 @@ func AddNonceAndPublicPlanToBuilds(tx migration.LimitedTx) error {
return err
}
- rows, err := tx.Query(`
+ offset := 0
+ for {
+ rows, err := tx.Query(fmt.Sprintf(`
SELECT id, engine_metadata
FROM builds
WHERE engine='exec.v2'
- `)
+ ORDER BY id ASC
+ LIMIT 500
+ OFFSET %d
+ `, offset))
if err != nil {
return err
}
@@ -38,7 +44,10 @@ func AddNonceAndPublicPlanToBuilds(tx migration.LimitedTx) error {
//create public plans
plans := map[int]internal.Plan{}
+ totalRows := 0
for rows.Next() {
+ totalRows++
+
var buildID int
var engineMetadataJSON []byte
err := rows.Scan(&buildID, &engineMetadataJSON)
@@ -59,6 +68,12 @@ func AddNonceAndPublicPlanToBuilds(tx migration.LimitedTx) error {
plans[buildID] = execEngineMetadata.Plan
}
+ if totalRows == 0 {
+ break
+ } else {
+ offset += totalRows
+ }
+
for buildID, plan := range plans {
_, err := tx.Exec(`
UPDATE builds
@@ -71,6 +86,7 @@ func AddNonceAndPublicPlanToBuilds(tx migration.LimitedTx) error {
return err
}
}
+ }
_, err = tx.Exec(`
UPDATE builds
