Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15269400
D18612.id44692.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D18612.id44692.diff
View Options
diff --git a/resources/sql/autopatches/20170915.ref.01.migrate.php b/resources/sql/autopatches/20170915.ref.01.migrate.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20170915.ref.01.migrate.php
@@ -0,0 +1,71 @@
+<?php
+
+$table = new PhabricatorRepositoryRefCursor();
+$conn = $table->establishConnection('w');
+
+$map = array();
+foreach (new LiskMigrationIterator($table) as $ref) {
+ $repository_phid = $ref->getRepositoryPHID();
+ $ref_type = $ref->getRefType();
+ $ref_hash = $ref->getRefNameHash();
+
+ $ref_key = "{$repository_phid}/{$ref_type}/{$ref_hash}";
+
+ if (!isset($map[$ref_key])) {
+ $map[$ref_key] = array(
+ 'id' => $ref->getID(),
+ 'type' => $ref_type,
+ 'hash' => $ref_hash,
+ 'repositoryPHID' => $repository_phid,
+ 'positions' => array(),
+ );
+ }
+
+ // NOTE: When this migration runs, the table will have "commitIdentifier" and
+ // "isClosed" fields. Later, it won't. Since they'll be removed, we can't
+ // rely on being able to access them via the object. Instead, run a separate
+ // raw query to read them.
+
+ $row = queryfx_one(
+ $conn,
+ 'SELECT commitIdentifier, isClosed FROM %T WHERE id = %d',
+ $ref->getTableName(),
+ $ref->getID());
+
+ $map[$ref_key]['positions'][] = array(
+ 'identifier' => $row['commitIdentifier'],
+ 'isClosed' => (int)$row['isClosed'],
+ );
+}
+
+// Now, write all the position rows.
+$position_table = new PhabricatorRepositoryRefPosition();
+foreach ($map as $ref_key => $spec) {
+ $id = $spec['id'];
+ foreach ($spec['positions'] as $position) {
+ queryfx(
+ $conn,
+ 'INSERT IGNORE INTO %T (cursorID, commitIdentifier, isClosed)
+ VALUES (%d, %s, %d)',
+ $position_table->getTableName(),
+ $id,
+ $position['identifier'],
+ $position['isClosed']);
+ }
+}
+
+// Finally, delete all the redundant RefCursor rows (rows with the same name)
+// so we can add proper unique keys in the next migration.
+foreach ($map as $ref_key => $spec) {
+ queryfx(
+ $conn,
+ 'DELETE FROM %T WHERE refType = %s
+ AND refNameHash = %s
+ AND repositoryPHID = %s
+ AND id != %d',
+ $table->getTableName(),
+ $spec['type'],
+ $spec['hash'],
+ $spec['repositoryPHID'],
+ $spec['id']);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Feb 27, 10:06 PM (7 h, 24 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7212810
Default Alt Text
D18612.id44692.diff (2 KB)
Attached To
Mode
D18612: Migrate RefCursor data to RefPosition table
Attached
Detach File
Event Timeline
Log In to Comment