From fbc175aa6e19abfdbb4c18a1d85bea01827d9b10 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 7 Nov 2014 12:30:00 -0800 Subject: [PATCH] Force Differential draft uniqueness Summary: Ref T1191. A couple of installs have hit issues with this table, so clean it up before adjustment adds a unique key to it. Test Plan: Dropped key, added duplicate rows, ran patch, got cleanup, ran adjust to get the key back. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T1191 Differential Revision: https://secure.phabricator.com/D10799 --- .../sql/autopatches/20141106.uniqdrafts.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 resources/sql/autopatches/20141106.uniqdrafts.php 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); +}