From 63302fd7b7f1924d81431d8e3020a56d54fa8a17 Mon Sep 17 00:00:00 2001 From: Zeno Tajoli Date: Wed, 18 Nov 2015 15:13:39 +0100 Subject: [PATCH] [BUG 15207] To not show errors on update from 3.20.x to 3.22.x Two update of db, 3.21.00.027 and 3.21.00.022, are partialy done also on 3.20.x. This patch modify updatedatabase.pl to cover those partial changes in db done in 3.20.x To test: 1)Install a 3.20.4 or more 2)Dump the db 2)Update to master and see the error 3)Installe the patch 4)Reload the db 5)Update to master and see no more error 6)Check the coerence at sql structure level More check: a)Reload the db b)Change db to delete the effect of those two commit in 3.20: bug 14205: http://git.koha-community.org/gitweb/?p=koha.git;a=commit;h=c158f9e27e9e283523a5070ae4e4c718627374d2 bug 14298: http://git.koha-community.org/gitweb/?p=koha.git;a=commit;h=e0c926e0104e3fb73d80d8bea07ea8b6f90807b3 c)Redone update d)With patch no errors --- installer/data/mysql/updatedatabase.pl | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 355656d..ac2903e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -10801,12 +10801,23 @@ if ( CheckVersion($DBversion) ) { LEFT JOIN course_items USING(ci_id) WHERE course_items.ci_id IS NULL }); - $dbh->do(q{ - ALTER IGNORE TABLE course_reserves - add CONSTRAINT course_reserves_ibfk_2 - FOREIGN KEY (ci_id) REFERENCES course_items (ci_id) - ON DELETE CASCADE ON UPDATE CASCADE - }); + + my $count_course_reserves_ibfk_2 = $dbh->selectrow_arrayref(q| + SELECT COUNT(*) + FROM information_schema.table_constraints + WHERE table_schema = schema() + AND table_name = 'course_reserves' + AND CONSTRAINT_NAME = 'course_reserves_ibfk_2' + |); + #Add fk only if not present + if ( $count_course_reserves_ibfk_2-->[0] == 0) { + $dbh->do(q{ + ALTER IGNORE TABLE course_reserves + add CONSTRAINT course_reserves_ibfk_2 + FOREIGN KEY (ci_id) REFERENCES course_items (ci_id) + ON DELETE CASCADE ON UPDATE CASCADE + }); + }; print "Upgrade to $DBversion done (Bug 14205: Deleting an Item/Record does not remove link to course reserve)\n"; SetVersion($DBversion); } @@ -10869,7 +10880,7 @@ if ( CheckVersion($DBversion) ) { $DBversion = "3.21.00.027"; if ( CheckVersion($DBversion) ) { $dbh->do(q| - INSERT INTO permissions (module_bit, code, description) + INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (1, 'self_checkout', 'Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID') |); -- 2.1.4