From 2b083cb82ae3af93307e45908bceb3e475209109 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 27 Aug 2021 14:39:51 +0200 Subject: [PATCH] Bug 22690: DBRev 21.06.00.018 Signed-off-by: Jonathan Druart --- Koha.pm | 2 +- .../data/mysql/atomicupdate/bug_22690.perl | 21 ---------------- installer/data/mysql/db_revs/210600018.pl | 25 +++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_22690.perl create mode 100755 installer/data/mysql/db_revs/210600018.pl diff --git a/Koha.pm b/Koha.pm index 26334714a7..fdeb021ba5 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "21.06.00.017"; +$VERSION = "21.06.00.018"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_22690.perl b/installer/data/mysql/atomicupdate/bug_22690.perl deleted file mode 100644 index 754372fc86..0000000000 --- a/installer/data/mysql/atomicupdate/bug_22690.perl +++ /dev/null @@ -1,21 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - unless( foreign_key_exists( 'linktracker', 'linktracker_biblio_ibfk' ) ) { - $dbh->do(q{ UPDATE linktracker SET biblionumber = NULL WHERE biblionumber NOT IN (SELECT biblionumber FROM biblio) }); - $dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_biblio_ibfk` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE SET NULL }); - } - - unless( foreign_key_exists( 'linktracker', 'linktracker_item_ibfk' ) ) { - $dbh->do(q{ UPDATE linktracker SET itemnumber = NULL WHERE itemnumber NOT IN (SELECT itemnumber FROM items) }); - $dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_item_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL }); - } - - unless( foreign_key_exists( 'linktracker', 'linktracker_borrower_ibfk' ) ) { - $dbh->do(q{ UPDATE linktracker SET borrowernumber = NULL WHERE borrowernumber NOT IN (SELECT borrowernumber FROM borrowers) }); - $dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_borrower_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL }); - } - - # Always end with this (adjust the bug info) - NewVersion( $DBversion, 22690, "Add constraints to linktracker table"); -} diff --git a/installer/data/mysql/db_revs/210600018.pl b/installer/data/mysql/db_revs/210600018.pl new file mode 100755 index 0000000000..b00e2b783e --- /dev/null +++ b/installer/data/mysql/db_revs/210600018.pl @@ -0,0 +1,25 @@ +use Modern::Perl; + +return { + bug_number => "22690", + description => "Add contraints to the linktracker table", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + unless( foreign_key_exists( 'linktracker', 'linktracker_biblio_ibfk' ) ) { + $dbh->do(q{ UPDATE linktracker SET biblionumber = NULL WHERE biblionumber NOT IN (SELECT biblionumber FROM biblio) }); + $dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_biblio_ibfk` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE SET NULL }); + } + + unless( foreign_key_exists( 'linktracker', 'linktracker_item_ibfk' ) ) { + $dbh->do(q{ UPDATE linktracker SET itemnumber = NULL WHERE itemnumber NOT IN (SELECT itemnumber FROM items) }); + $dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_item_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL }); + } + + unless( foreign_key_exists( 'linktracker', 'linktracker_borrower_ibfk' ) ) { + $dbh->do(q{ UPDATE linktracker SET borrowernumber = NULL WHERE borrowernumber NOT IN (SELECT borrowernumber FROM borrowers) }); + $dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_borrower_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL }); + } + }, +} -- 2.39.5