From 3a2e921f6675c8ae31f8c68f4a7f5696c8b09a8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Delaune?= <stephane.delaune@biblibre.com>
Date: Thu, 22 Mar 2012 11:34:35 +0100
Subject: [PATCH] Bug 7792:redefine the field branchcode as PRIMARY KEY of
 branches

---
 installer/data/mysql/kohastructure.sql |    1 +
 installer/data/mysql/updatedatabase.pl |    7 +++++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index f5d8a24..4faed15 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -362,6 +362,7 @@ CREATE TABLE `branches` ( -- information about your libraries or branches are st
   `branchip` varchar(15) default NULL, -- the IP address for your library or branch
   `branchprinter` varchar(100) default NULL, -- unused in Koha
   `branchnotes` mediumtext, -- notes related to your library or branch
+  PRIMARY KEY (`branchcode`),
   UNIQUE KEY `branchcode` (`branchcode`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 32099d8..d7bd3a9 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4994,6 +4994,13 @@ if ( C4::Context->preference("Version") lt TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
+$DBversion = "XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE branches ADD PRIMARY KEY (branchcode);");
+    print "Upgrade to $DBversion done (redefine the field branchcode as PRIMARY KEY of branches)\n";
+    SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
-- 
1.7.5.4