1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-28 12:08:14 +01:00

Migrate old AuxiliaryField storage to modern CustomField storage

Summary: Ref T2222. Ref T3886. Differential has a legacy storage table for auxiliary fields; move the data to modern storage.

Test Plan:
  - Ran migration.
  - Verified fields still worked properly afterward (view, edit, etc).

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3886, T2222

Differential Revision: https://secure.phabricator.com/D8355
This commit is contained in:
epriestley 2014-02-26 16:52:30 -08:00
parent ee2b6eebaa
commit cd7171ec6e
5 changed files with 45 additions and 36 deletions

View file

@ -0,0 +1,22 @@
<?php
$conn_w = id(new DifferentialRevision())->establishConnection('w');
$rows = new LiskRawMigrationIterator($conn_w, 'differential_auxiliaryfield');
echo "Modernizing Differential auxiliary field storage...\n";
$table_name = id(new DifferentialCustomFieldStorage())->getTableName();
foreach ($rows as $row) {
$id = $row['id'];
echo "Migrating row {$id}...\n";
queryfx(
$conn_w,
'INSERT IGNORE INTO %T (objectPHID, fieldIndex, fieldValue)
VALUES (%s, %s, %s)',
$table_name,
$row['revisionPHID'],
PhabricatorHash::digestForIndex($row['name']),
$row['value']);
}
echo "Done.\n";

View file

@ -2891,7 +2891,6 @@ phutil_register_library_map(array(
'DifferentialAuditorsFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialAuditorsFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialAuthorField' => 'DifferentialCustomField', 'DifferentialAuthorField' => 'DifferentialCustomField',
'DifferentialAuthorFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialAuthorFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialAuxiliaryField' => 'DifferentialDAO',
'DifferentialBlameRevisionFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialBlameRevisionFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialBranchFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialBranchFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialCCWelcomeMail' => 'DifferentialReviewRequestMail', 'DifferentialCCWelcomeMail' => 'DifferentialReviewRequestMail',

View file

@ -707,14 +707,14 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
$revision = $this->revision; $revision = $this->revision;
$fields = id(new DifferentialAuxiliaryField())->loadAllWhere( $fields = id(new DifferentialCustomFieldStorage())->loadAllWhere(
'revisionPHID = %s AND name IN (%Ls)', 'objectPHID = %s',
$revision->getPHID(), $revision->getPHID());
array_keys($aux_map)); $fields = mpull($fields, null, 'getFieldIndex');
$fields = mpull($fields, null, 'getName');
foreach ($aux_map as $key => $val) { foreach ($aux_map as $key => $val) {
$obj = idx($fields, $key); $index = PhabricatorHash::digestForIndex($key);
$obj = idx($fields, $index);
if (!strlen($val)) { if (!strlen($val)) {
// If the new value is empty, just delete the old row if one exists and // If the new value is empty, just delete the old row if one exists and
// don't add a new row if it doesn't. // don't add a new row if it doesn't.
@ -723,9 +723,9 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
} }
} else { } else {
if (!$obj) { if (!$obj) {
$obj = new DifferentialAuxiliaryField(); $obj = new DifferentialCustomFieldStorage();
$obj->setRevisionPHID($revision->getPHID()); $obj->setObjectPHID($revision->getPHID());
$obj->setName($key); $obj->setFieldIndex($index);
} }
if ($obj->getValue() !== $val) { if ($obj->getValue() !== $val) {

View file

@ -1,20 +1,6 @@
<?php <?php
final class DifferentialAuxiliaryField extends DifferentialDAO { final class DifferentialAuxiliaryField {
protected $revisionPHID;
protected $name;
protected $value;
public function setName($name) {
if (strlen($name) > 32) {
throw new Exception(
"Tried to set name '{$name}' for a Differential auxiliary field; ".
"auxiliary field names must be no longer than 32 characters.");
}
$this->name = $name;
return $this;
}
public static function loadFromStorage( public static function loadFromStorage(
DifferentialRevision $revision, DifferentialRevision $revision,
@ -24,11 +10,20 @@ final class DifferentialAuxiliaryField extends DifferentialDAO {
$storage_keys = array_filter(mpull($aux_fields, 'getStorageKey')); $storage_keys = array_filter(mpull($aux_fields, 'getStorageKey'));
$field_data = array(); $field_data = array();
if ($storage_keys) { if ($storage_keys) {
$field_data = id(new DifferentialAuxiliaryField())->loadAllWhere( $index_map = array();
'revisionPHID = %s AND name IN (%Ls)', foreach ($storage_keys as $key) {
$index_map[PhabricatorHash::digestForIndex($key)] = $key;
}
$index_data = id(new DifferentialCustomFieldStorage())->loadAllWhere(
'objectPHID = %s AND fieldIndex IN (%Ls)',
$revision->getPHID(), $revision->getPHID(),
$storage_keys); array_keys($index_map));
$field_data = mpull($field_data, 'getValue', 'getName'); $index_data = mpull($index_data, 'getFieldValue', 'getFieldIndex');
foreach ($index_data as $index => $data) {
$field_data[$index_map[$index]] = $data;
}
} }
foreach ($aux_fields as $aux_field) { foreach ($aux_fields as $aux_field) {

View file

@ -209,13 +209,6 @@ final class DifferentialRevision extends DifferentialDAO
$inline->delete(); $inline->delete();
} }
$fields = id(new DifferentialAuxiliaryField())->loadAllWhere(
'revisionPHID = %s',
$this->getPHID());
foreach ($fields as $field) {
$field->delete();
}
// we have to do paths a little differentally as they do not have // we have to do paths a little differentally as they do not have
// an id or phid column for delete() to act on // an id or phid column for delete() to act on
$dummy_path = new DifferentialAffectedPath(); $dummy_path = new DifferentialAffectedPath();