From aad5650bf689b71fb1c755b95c042b27bba5d93b Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Fri, 20 Dec 2013 15:03:16 +0100
Subject: [PATCH] [PASSED QA] Bug 11430: DB changes: Add the primary key for search_history

Adds a primary key search_history.id.

Signed-off-by: sonia BOUIS <sonia.bouis@univ-lyon3.fr>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 installer/data/mysql/kohastructure.sql |    4 +++-
 installer/data/mysql/updatedatabase.pl |   18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index b46dc6a..fa722a4 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1908,6 +1908,7 @@ CREATE TABLE saved_reports (
 
 DROP TABLE IF EXISTS `search_history`;
 CREATE TABLE IF NOT EXISTS `search_history` ( -- patron's opac search history
+  `ìd` int(11) NOT NULL auto_increment, -- search history id
   `userid` int(11) NOT NULL, -- the patron who performed the search (borrowers.borrowernumber)
   `sessionid` varchar(32) NOT NULL, -- a system generated session id
   `query_desc` varchar(255) NOT NULL, -- the search that was performed
@@ -1916,7 +1917,8 @@ CREATE TABLE IF NOT EXISTS `search_history` ( -- patron's opac search history
   `total` int(11) NOT NULL, -- the total of results found
   `time` timestamp NOT NULL default CURRENT_TIMESTAMP, -- the date and time the search was run
   KEY `userid` (`userid`),
-  KEY `sessionid` (`sessionid`)
+  KEY `sessionid` (`sessionid`),
+  PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
 
 
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index c68ba51..e60fa35 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -8560,6 +8560,24 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
+
+
+
+
+
+
+
+$DBversion = "3.17.00.XXX";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        ALTER TABLE search_history ADD COLUMN id INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY(id);
+    |);
+    print "Upgrade to $DBversion done (Bug 11430 - Add primary key for search_history)\n";
+    SetVersion($DBversion);
+}
+
+
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
-- 
1.7.2.5