@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3$table = new AlmanacNetwork();
4$conn = $table->establishConnection('w');
5
6queryfx(
7 $conn,
8 'LOCK TABLES %T WRITE',
9 $table->getTableName());
10
11$seen = array();
12foreach (new LiskMigrationIterator($table) as $network) {
13 $name = $network->getName();
14
15 // If this is the first copy of this row we've seen, mark it as seen and
16 // move on.
17 if (empty($seen[$name])) {
18 $seen[$name] = 1;
19 continue;
20 }
21
22 // Otherwise, rename this row.
23 while (true) {
24 $new_name = $name.'-'.$seen[$name];
25 if (empty($seen[$new_name])) {
26 $network->setName($new_name);
27 try {
28 $network->save();
29 break;
30 } catch (AphrontDuplicateKeyQueryException $ex) {
31 // New name is a dupe of a network we haven't seen yet.
32 }
33 }
34 $seen[$name]++;
35 }
36 $seen[$new_name] = 1;
37}
38
39queryfx(
40 $conn,
41 'ALTER TABLE %T ADD UNIQUE KEY `key_name` (name)',
42 $table->getTableName());
43
44queryfx(
45 $conn,
46 'UNLOCK TABLES');