[Koha-patches] [PATCH] Bugfix: borrowers.userid is not defined as a unique key

Chris Nighswonger cnighswonger at foundations.edu
Fri Feb 5 17:35:11 CET 2010


While this constraint is enforced by memberentry.pl, it is not
enforced by import_borrowers.pl and in any case should be enforced
by the database in case custome patron import/update scripts are
being run.
---
 installer/data/mysql/kohastructure.sql |    2 +-
 installer/data/mysql/updatedatabase.pl |   21 ++++++++++++++-------
 kohaversion.pl                         |    2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index b700a17..9258743 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -240,7 +240,7 @@ CREATE TABLE `borrowers` (
   `sex` varchar(1) default NULL,
   `password` varchar(30) default NULL,
   `flags` int(11) default NULL,
-  `userid` varchar(30) default NULL,
+  `userid` varchar(30) UNIQUE default NULL,
   `opacnote` mediumtext,
   `contactnote` varchar(255) default NULL,
   `sort1` varchar(80) default NULL,
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index f44c257..6b26c1e 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2726,7 +2726,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 $DBversion = '3.01.00.066';
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;');
-    
+
     my $maxreserves = C4::Context->preference('maxreserves');
     $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;');
     $sth->execute($maxreserves);
@@ -3270,10 +3270,10 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 $DBversion = "3.01.00.101";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 	$dbh->do(
-        "INSERT INTO systempreferences 
+        "INSERT INTO systempreferences
            (variable, value, options, explanation, type)
          VALUES (
-            'OverdueNoticeBcc', '', '', 
+            'OverdueNoticeBcc', '', '',
             'Email address to Bcc outgoing notices sent by email',
             'free')
          ");
@@ -3308,7 +3308,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     if ($borrnotes_count == 0) {
         $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('BOR_NOTES','ADDR','Address Notes')");
     }
-    
+
     $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOC','CART','Book Cart')");
     $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOC','PROC','Processing Center')");
 
@@ -3328,7 +3328,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
         PRIMARY KEY  (`colId`)
       ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     ");
-       
+
     $dbh->do("
       CREATE TABLE `collections_tracking` (
         `ctId` int(11) NOT NULL auto_increment,
@@ -3338,7 +3338,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
       ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     ");
     $dbh->do("
-        INSERT INTO permissions (module_bit, code, description) 
+        INSERT INTO permissions (module_bit, code, description)
         VALUES ( 13, 'rotating_collections', 'Manage Rotating collections')" );
 	print "Upgrade to $DBversion done (added collection and collection_tracking tables for rotating collections functionality)\n";
     SetVersion ($DBversion);
@@ -3363,7 +3363,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 	$dbh->do(qq{
 	ALTER TABLE `export_format` ADD `csv_separator` VARCHAR( 2 ) NOT NULL AFTER `marcfields` ,
 	ADD `field_separator` VARCHAR( 2 ) NOT NULL AFTER `csv_separator` ,
-	ADD `subfield_separator` VARCHAR( 2 ) NOT NULL AFTER `field_separator` 
+	ADD `subfield_separator` VARCHAR( 2 ) NOT NULL AFTER `field_separator`
 	});
 	print "Upgrade done (added separators for csv export)\n";
     SetVersion ($DBversion);
@@ -3398,6 +3398,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = '3.01.00.113';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE borrowers CHANGE COLUMN userid `userid` varchar(30) UNIQUE DEFAULT NULL;");
+    print "Upgrade done ( Made borrowers.userid a unique key to ensure against duplicate userid's. )\n";
+    SetVersion ($DBversion);
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
diff --git a/kohaversion.pl b/kohaversion.pl
index 5cfd314..1748ebc 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -10,7 +10,7 @@
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.01.00.112';
+    our $VERSION = '3.01.00.113';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
-- 
1.6.0.4



More information about the Koha-patches mailing list