diff --git a/resources/sql/patches/131.migraterevisionquery.php b/resources/sql/patches/131.migraterevisionquery.php index aacb1ea9df..2876047552 100644 --- a/resources/sql/patches/131.migraterevisionquery.php +++ b/resources/sql/patches/131.migraterevisionquery.php @@ -19,26 +19,29 @@ $table = new DifferentialRevision(); $conn_w = $table->establishConnection('w'); -$revisions = id(new DifferentialRevision())->loadAll(); +echo "Migrating revisions"; +do { + $revisions = id(new DifferentialRevision()) + ->loadAllWhere('branchName IS NULL LIMIT 1000'); -echo "Migrating ".count($revisions)." revisions"; -foreach ($revisions as $revision) { - echo "."; + foreach ($revisions as $revision) { + echo "."; - $diff = $revision->loadActiveDiff(); - if (!$diff) { - continue; + $diff = $revision->loadActiveDiff(); + if (!$diff) { + continue; + } + + $branch_name = $diff->getBranch(); + $arc_project_phid = $diff->getArcanistProjectPHID(); + + queryfx( + $conn_w, + 'UPDATE %T SET branchName = %s, arcanistProjectPHID = %s WHERE id = %d', + $table->getTableName(), + $branch_name, + $arc_project_phid, + $revision->getID()); } - - $branch_name = $diff->getBranch(); - $arc_project_phid = $diff->getArcanistProjectPHID(); - - queryfx( - $conn_w, - 'UPDATE %T SET branchName = %s, arcanistProjectPHID = %s WHERE id = %d', - $table->getTableName(), - $branch_name, - $arc_project_phid, - $revision->getID()); -} +} while (count($revisions) == 1000); echo "\nDone.\n";