From 875108d46e0dacec4221261a29e680023fa5167d Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 4 May 2018 10:42:38 +0200 Subject: [PATCH] Bug 20754: DB revision to remove double accepted shares [Originally submitted for bug 11943, parked at 20754.] [Attempt to revive it now.] Although it is no problem to have them, we could do a cleanup. This patch just removes duplicate rows from the table. Note: I considered adding a unique index like: ALTER TABLE virtualshelfshares ADD UNIQUE INDEX (shelfnumber, borrowernumber, invitekey); But the possible NULL values in borrowernumber and/or invitekey require additional code changes. So I left it alone. Test plan: [1] Create two records with same borrowernumber and shelfnumber in the shares table, if not present already. [2] Run updatedatabase.pl Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- installer/data/mysql/atomicupdate/bug20754.perl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug20754.perl diff --git a/installer/data/mysql/atomicupdate/bug20754.perl b/installer/data/mysql/atomicupdate/bug20754.perl new file mode 100644 index 0000000000..b819674141 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug20754.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + # From: https://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql + $dbh->do(q| +DELETE a +FROM virtualshelfshares as a, virtualshelfshares as b +WHERE a.id < b.id AND a.borrowernumber IS NOT NULL AND a.borrowernumber=b.borrowernumber AND a.shelfnumber=b.shelfnumber + |); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 20754: Remove double accepted list shares)\n"; +} -- 2.39.5