mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Migrate all Differential comment text into new storage
Summary: Ref T2222. Currently, `DifferentialComment` stores both (a) the text of comments and (b) various other transaction details. This data needs to map to both Transactions and TransactionComments in the long run. This diff separates out all the data which is bound for the TransactionComment table, so that when we migrate `DifferentialComment` itself it will //only// need to migrate into the Transactions table. This is a much simpler migration than the inline comment one was, partly because it set up infrastructure and partly because the data is less complex. Basically, I'm just proxying the read/write for the comment text into the other table. All readers already go through the Query class, and there are only three writers (preview, comment, implicit comment on diff update) which are all highly regular and straightforward to test. We can also back out of this diff very easily: doing double writes cost only one line of code (`$this->content = $content;`) so we have proper double writes and a trivial revert path. Test Plan: - Without migrating, added comments and saw them show up. - Migrated. - Saw all the old comments, and no damage to the new ones. - Added new comments. - Used comment preview. - Updated a revision to implicitly create an update comment and verified it looked OK. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8196
This commit is contained in:
parent
3a01d6dae5
commit
305fb3fbd9
4 changed files with 161 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_differential.differential_transaction_comment
|
||||
CHANGE changesetID changesetID INT UNSIGNED;
|
71
resources/sql/autopatches/20140211.dx.2.migcommenttext.php
Normal file
71
resources/sql/autopatches/20140211.dx.2.migcommenttext.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
$conn_w = id(new DifferentialRevision())->establishConnection('w');
|
||||
$rows = new LiskRawMigrationIterator($conn_w, 'differential_comment');
|
||||
|
||||
$content_source = PhabricatorContentSource::newForSource(
|
||||
PhabricatorContentSource::SOURCE_LEGACY,
|
||||
array())->serialize();
|
||||
|
||||
echo "Migrating Differential comment text to modern storage...\n";
|
||||
foreach ($rows as $row) {
|
||||
$id = $row['id'];
|
||||
echo "Migrating Differential comment {$id}...\n";
|
||||
if (!strlen($row['content'])) {
|
||||
echo "Comment has no text, continuing.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$revision = id(new DifferentialRevision())->load($row['revisionID']);
|
||||
if (!$revision) {
|
||||
echo "Comment has no valid revision, continuing.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$revision_phid = $revision->getPHID();
|
||||
|
||||
$dst_table = 'differential_inline_comment';
|
||||
|
||||
$xaction_phid = PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorApplicationTransactionPHIDTypeTransaction::TYPECONST,
|
||||
DifferentialPHIDTypeRevision::TYPECONST);
|
||||
|
||||
$comment_phid = PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_XCMT,
|
||||
DifferentialPHIDTypeRevision::TYPECONST);
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'INSERT IGNORE INTO %T
|
||||
(phid, transactionPHID, authorPHID, viewPolicy, editPolicy,
|
||||
commentVersion, content, contentSource, isDeleted,
|
||||
dateCreated, dateModified, revisionPHID, changesetID,
|
||||
legacyCommentID)
|
||||
VALUES (%s, %s, %s, %s, %s,
|
||||
%d, %s, %s, %d,
|
||||
%d, %d, %s, %nd,
|
||||
%d)',
|
||||
'differential_transaction_comment',
|
||||
|
||||
// phid, transactionPHID, authorPHID, viewPolicy, editPolicy
|
||||
$comment_phid,
|
||||
$xaction_phid,
|
||||
$row['authorPHID'],
|
||||
'public',
|
||||
$row['authorPHID'],
|
||||
|
||||
// commentVersion, content, contentSource, isDeleted
|
||||
1,
|
||||
$row['content'],
|
||||
$content_source,
|
||||
0,
|
||||
|
||||
// dateCreated, dateModified, revisionPHID, changesetID, legacyCommentID
|
||||
$row['dateCreated'],
|
||||
$row['dateModified'],
|
||||
$revision_phid,
|
||||
null,
|
||||
$row['id']);
|
||||
}
|
||||
|
||||
echo "Done.\n";
|
|
@ -24,7 +24,15 @@ final class DifferentialCommentQuery
|
|||
$this->buildWhereClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
$comments = $table->loadAllFromArray($data);
|
||||
|
||||
// We've moved the actual text storage into DifferentialTransactionComment,
|
||||
// so load the relevant pieces of text we need.
|
||||
if ($comments) {
|
||||
$this->loadCommentText($comments);
|
||||
}
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
|
@ -40,4 +48,25 @@ final class DifferentialCommentQuery
|
|||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function loadCommentText(array $comments) {
|
||||
$table = new DifferentialTransactionComment();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T WHERE legacyCommentID IN (%Ld) AND changesetID IS NULL',
|
||||
$table->getTableName(),
|
||||
mpull($comments, 'getID'));
|
||||
$texts = $table->loadAllFromArray($data);
|
||||
$texts = mpull($texts, null, 'getLegacyCommentID');
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
$text = idx($texts, $comment->getID());
|
||||
if ($text) {
|
||||
$comment->setProxyComment($text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,14 +13,44 @@ final class DifferentialComment extends DifferentialDAO
|
|||
protected $authorPHID;
|
||||
protected $revisionID;
|
||||
protected $action;
|
||||
protected $content;
|
||||
protected $content = '';
|
||||
protected $cache;
|
||||
protected $metadata = array();
|
||||
protected $contentSource;
|
||||
|
||||
private $arbitraryDiffForFacebook;
|
||||
private $proxyComment;
|
||||
|
||||
public function getContent() {
|
||||
return $this->getProxyComment()->getContent();
|
||||
}
|
||||
|
||||
public function setContent($content) {
|
||||
// NOTE: We no longer read this field, but there's no cost to continuing
|
||||
// to write it in case something goes horribly wrong, since it makes it
|
||||
// far easier to back out of this.
|
||||
$this->content = $content;
|
||||
$this->getProxyComment()->setContent($content);
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getProxyComment() {
|
||||
if (!$this->proxyComment) {
|
||||
$this->proxyComment = new DifferentialTransactionComment();
|
||||
}
|
||||
return $this->proxyComment;
|
||||
}
|
||||
|
||||
public function setProxyComment(DifferentialTransactionComment $proxy) {
|
||||
if ($this->proxyComment) {
|
||||
throw new Exception(pht('You can not overwrite a proxy comment.'));
|
||||
}
|
||||
$this->proxyComment = $proxy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRevision(DifferentialRevision $revision) {
|
||||
$this->getProxyComment()->setRevisionPHID($revision->getPHID());
|
||||
return $this->setRevisionID($revision->getID());
|
||||
}
|
||||
|
||||
|
@ -93,4 +123,31 @@ final class DifferentialComment extends DifferentialDAO
|
|||
return (bool)$this->getID();
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$this->openTransaction();
|
||||
$result = parent::save();
|
||||
|
||||
$content_source = PhabricatorContentSource::newForSource(
|
||||
PhabricatorContentSource::SOURCE_LEGACY,
|
||||
array());
|
||||
|
||||
$xaction_phid = PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorApplicationTransactionPHIDTypeTransaction::TYPECONST,
|
||||
DifferentialPHIDTypeRevision::TYPECONST);
|
||||
|
||||
$proxy = $this->getProxyComment();
|
||||
$proxy
|
||||
->setAuthorPHID($this->getAuthorPHID())
|
||||
->setViewPolicy('public')
|
||||
->setEditPolicy($this->getAuthorPHID())
|
||||
->setContentSource($content_source)
|
||||
->setCommentVersion(1)
|
||||
->setLegacyCommentID($this->getID())
|
||||
->setTransactionPHID($xaction_phid)
|
||||
->save();
|
||||
$this->saveTransaction();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue