5860 Fixing stocknumber index

Fixing code for 3.3.0.42 update.
Adding code at end of update script if install past that point already.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
Marcel de Rooy 2011-05-16 10:57:49 +02:00 committed by Chris Cormack
parent 3cf27546c9
commit a3717c1fe9

View file

@ -4216,13 +4216,27 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
} }
$DBversion = '3.03.00.042'; $DBversion = '3.03.00.042';
if (C4::Context->preference("Version") < TransformToNum($DBversion) && $original_version < TransformToNum("3.02.06.001")) { if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `items` DROP INDEX `itemsstocknumberidx`;"); stocknumber_checker();
$dbh->do("ALTER TABLE items ADD INDEX itemstocknumberidx (stocknumber);"); print "Upgrade to $DBversion done (5860 Index itemstocknumber)\n";
print "Upgrade to $DBversion done (Change items.stocknumber to be not unique)\n";
SetVersion ($DBversion); SetVersion ($DBversion);
} }
sub stocknumber_checker { #code reused later on
my @row;
#drop the obsolete itemSStocknumber idx if it exists
@row = $dbh->selectrow_array("SHOW INDEXES FROM items WHERE key_name='itemsstocknumberidx'");
$dbh->do("ALTER TABLE `items` DROP INDEX `itemsstocknumberidx`;") if @row;
#check itemstocknumber idx; remove it if it is unique
@row = $dbh->selectrow_array("SHOW INDEXES FROM items WHERE key_name='itemstocknumberidx' AND non_unique=0");
$dbh->do("ALTER TABLE `items` DROP INDEX `itemstocknumberidx`;") if @row;
#add itemstocknumber index non-unique IF it still not exists
@row = $dbh->selectrow_array("SHOW INDEXES FROM items WHERE key_name='itemstocknumberidx'");
$dbh->do("ALTER TABLE items ADD INDEX itemstocknumberidx (stocknumber);") unless @row;
}
$DBversion = "3.03.00.043"; $DBversion = "3.03.00.043";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) { if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
@ -4332,6 +4346,14 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
SetVersion($DBversion); SetVersion($DBversion);
} }
$DBversion = '3.05.00.XXX';
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
#follow up fix 5860: some installs already past 3.3.0.42
stocknumber_checker();
print "Upgrade to $DBversion done (Fix for stocknumber index)\n";
SetVersion ($DBversion);
}
=head1 FUNCTIONS =head1 FUNCTIONS
=head2 DropAllForeignKeys($table) =head2 DropAllForeignKeys($table)