From 08297c9495a80de9689049a928362ee5e82d53ab Mon Sep 17 00:00:00 2001 From: Yohann Dufour Date: Thu, 7 Aug 2014 16:40:06 +0200 Subject: [PATCH] Bug 10363: DB Changes: Adds a unique key for the authorised values table. --- Koha/Schema/Result/AuthorisedValue.pm | 20 ++++++++++++++++++-- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 10 ++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Koha/Schema/Result/AuthorisedValue.pm b/Koha/Schema/Result/AuthorisedValue.pm index 0366aec..e1495b2 100644 --- a/Koha/Schema/Result/AuthorisedValue.pm +++ b/Koha/Schema/Result/AuthorisedValue.pm @@ -90,6 +90,22 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("av_uniq", ["category", "authorised_value"]); + =head1 RELATIONS =head2 authorised_values_branches @@ -108,8 +124,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:N6Q7Y4sHL03X170zJ3APUA +# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-08-05 16:05:45 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9LllSeL5DPjwR2ucEOqU8w # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index b46dc6a..102f367 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -104,6 +104,7 @@ CREATE TABLE `authorised_values` ( -- stores values for authorized values catego `lib_opac` varchar(200) default NULL, -- authorized value description as printed in the OPAC `imageurl` varchar(200) default NULL, -- authorized value URL PRIMARY KEY (`id`), + UNIQUE KEY `av_uniq` (`category`,`authorised_value`), KEY `name` (`category`), KEY `lib` (`lib`), KEY `auth_value_idx` (`authorised_value`) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 531bb12..8f271c6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8589,6 +8589,16 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + ALTER TABLE authorised_values ADD UNIQUE KEY av_uniq(category, authorised_value); + }); + print "Upgrade to $DBversion done (Bug XXXXX: Add unique key on the authorised_values table)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) -- 1.9.1