diff --git a/resources/sql/autopatches/20141106.uniqdrafts.php b/resources/sql/autopatches/20141106.uniqdrafts.php new file mode 100644 index 0000000000..31d6a53cb7 --- /dev/null +++ b/resources/sql/autopatches/20141106.uniqdrafts.php @@ -0,0 +1,30 @@ +establishConnection('w'); + +$duplicates = queryfx_all( + $conn_w, + 'SELECT DISTINCT u.id id FROM %T u + JOIN %T v + ON u.objectPHID = v.objectPHID + AND u.authorPHID = v.authorPHID + AND u.draftKey = v.draftKey + AND u.id < v.id', + $table->getTableName(), + $table->getTableName()); + +$duplicates = ipull($duplicates, 'id'); +foreach (PhabricatorLiskDAO::chunkSQL($duplicates) as $chunk) { + queryfx( + $conn_w, + 'DELETE FROM %T WHERE id IN (%Q)', + $table->getTableName(), + $chunk); +}