@@ -, +, @@ --- .../data/mysql/atomicupdate/bug_21065.perl | 22 +++++++++++-------- installer/data/mysql/kohastructure.sql | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) --- a/installer/data/mysql/atomicupdate/bug_21065.perl +++ a/installer/data/mysql/atomicupdate/bug_21065.perl @@ -1,15 +1,19 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { - $dbh->do(q| - ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_1; - |); - $dbh->do(q| - ALTER TABLE accountlines CHANGE COLUMN borrowernumber borrowernumber INT(11) DEFAULT NULL; - |); - $dbh->do(q| - ALTER TABLE accountlines ADD CONSTRAINT accountlines_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE SET NULL ON UPDATE CASCADE; - |); + my $sth = $dbh->prepare(q|SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME='accountlines_ibfk_1'|); + $sth->execute; + if ($sth->fetchrow_hashref) { + $dbh->do(q| + ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_1; + |); + $dbh->do(q| + ALTER TABLE accountlines CHANGE COLUMN borrowernumber borrowernumber INT(11) DEFAULT NULL; + |); + $dbh->do(q| + ALTER TABLE accountlines ADD CONSTRAINT accountlines_ibfk_borrowers FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE SET NULL ON UPDATE CASCADE; + |); + } SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 21065 - Set ON DELETE SET NULL on accountlines.borrowernumber)\n"; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2722,7 +2722,7 @@ CREATE TABLE `accountlines` ( KEY `acctsborridx` (`borrowernumber`), KEY `timeidx` (`timestamp`), KEY `itemnumber` (`itemnumber`), - CONSTRAINT `accountlines_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `accountlines_ibfk_borrowers` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `accountlines_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; --