From 3999741d4a753ba593e4716618deac2141c4c889 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 14 Apr 2020 17:21:25 +0100 Subject: [PATCH] Bug 22887: DBRev 19.12.00.071 Signed-off-by: Martin Renvoize --- Koha.pm | 2 +- .../data/mysql/atomicupdate/bug_22887.perl | 24 ------------- installer/data/mysql/updatedatabase.pl | 34 +++++++++++++++++++ 3 files changed, 35 insertions(+), 25 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_22887.perl diff --git a/Koha.pm b/Koha.pm index 41f77b1400..b626d6eef2 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 = "19.12.00.070"; +$VERSION = "19.12.00.071"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_22887.perl b/installer/data/mysql/atomicupdate/bug_22887.perl deleted file mode 100644 index f3dca7d4ca..0000000000 --- a/installer/data/mysql/atomicupdate/bug_22887.perl +++ /dev/null @@ -1,24 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - unless ( index_exists('authorised_values', 'av_uniq') ) { - $dbh->do(q| - DELETE FROM authorised_values - WHERE category="COUNTRY" AND authorised_value="CC" AND lib="Keeling" - |); - my $duplicates = $dbh->selectall_arrayref(q| - SELECT category, authorised_value, COUNT(concat(category, ':', authorised_value)) AS c - FROM authorised_values - GROUP BY category, authorised_value - HAVING c > 1 - |, { Slice => {} }); - if ( @$duplicates ) { - warn "WARNING - Cannot create unique constraint on authorised_value(category, authorised_value)\n"; - warn "The following entries are duplicated: " . join (', ', map { sprintf "%s:%s (%s)", $_->{category}, $_->{authorised_value}, $_->{c} } @$duplicates); - } else { - $dbh->do( q{ALTER TABLE `authorised_values` ADD CONSTRAINT `av_uniq` UNIQUE (category, authorised_value)} ); - } - } - - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 22887 - Add unique constraint to authorised_values)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f3d927cd53..4590eadc01 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -21565,6 +21565,40 @@ if( CheckVersion( $DBversion ) ) { NewVersion( $DBversion, 22774, "Limit purchase suggestion in a specified time period"); } +$DBversion = '19.12.00.071'; +if( CheckVersion( $DBversion ) ) { + my @description = ("Add unique constraint to authorised_values"); + unless ( index_exists('authorised_values', 'av_uniq') ) { + $dbh->do(q| + DELETE FROM authorised_values + WHERE category="COUNTRY" AND authorised_value="CC" AND lib="Keeling" + |); + my $duplicates = $dbh->selectall_arrayref(q| + SELECT category, authorised_value, COUNT(concat(category, ':', authorised_value)) AS c + FROM authorised_values + GROUP BY category, authorised_value + HAVING c > 1 + |, { Slice => {} }); + if ( @$duplicates ) { + push @description, "WARNING - Cannot create unique constraint on authorised_value(category, authorised_value)"; + push @description, "The following entries are duplicated: " . join( + ', ', + map { + sprintf "%s:%s (%s)", $_->{category}, + $_->{authorised_value}, $_->{c} + } @$duplicates + ); + for my $error (@description) { + warn $error . "\n"; + } + } else { + $dbh->do( q{ALTER TABLE `authorised_values` ADD CONSTRAINT `av_uniq` UNIQUE (category, authorised_value)} ); + } + } + + NewVersion( $DBversion, 22887, \@description ); +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/'; -- 2.20.1