X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=installer%2Fdata%2Fmysql%2Fupdatedatabase.pl;h=ab2711ce463d6fd72ffffcd867760d43d2854480;hb=f8c20ac4c91f22017093a2d8ed0dbb8b0a3738bc;hp=527c5cedb0cf06a7660ac5412c3db7888d4eaf6c;hpb=ee1f262f1466e96e9676b3650fe2300b55565d53;p=koha.git diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 527c5cedb0..ab2711ce46 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17771,6 +17771,26 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 21683 - Remove accountlines.accountno and statistics.proccode fields)\n"; } +$DBversion = '18.12.00.031'; +if( CheckVersion( $DBversion ) ) { + + # Add constraint for manager_id + unless( foreign_key_exists( 'accountlines', 'accountlines_ibfk_borrowers_2' ) ) { + $dbh->do("ALTER TABLE accountlines CHANGE COLUMN manager_id manager_id INT(11) NULL DEFAULT NULL"); + $dbh->do("UPDATE accountlines a LEFT JOIN borrowers b ON ( a.manager_id = b.borrowernumber) SET a.manager_id = NULL WHERE b.borrowernumber IS NULL"); + $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE"); + } + + # Rename accountlines_ibfk_2 to accountlines_ibfk_items + if ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_2' ) && !foreign_key_exists( 'accountlines', 'accountlines_ibfk_items' ) ) { + $dbh->do("ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_2"); + $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE"); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 22008 - Add missing constraints for accountlines.manager_id)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it.