added auto_number column as PK for action_logs
authorGalen Charlton <galen.charlton@liblime.com>
Wed, 31 Oct 2007 00:16:47 +0000 (19:16 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 31 Oct 2007 10:55:25 +0000 (05:55 -0500)
* prevents PK warnings when logging actions that occur
  faster than once a second (e.g., batch MARC loads) --
  the original PK of timestamp + user not granular enough
* timestamp + user still indexed for log viewing

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
installer/kohastructure.sql
kohaversion.pl
updater/updatedatabase

index 5bbf29a..61bb52b 100644 (file)
@@ -59,13 +59,15 @@ CREATE TABLE `accountoffsets` (
 
 DROP TABLE IF EXISTS `action_logs`;
 CREATE TABLE `action_logs` (
+  `action_id` int(11) NOT NULL auto_increment,
   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
   `user` int(11) NOT NULL default 0,
   `module` text,
   `action` text,
   `object` int(11) default NULL,
   `info` text,
-  PRIMARY KEY  (`timestamp`,`user`)
+  PRIMARY KEY (`action_id`),
+  KEY  (`timestamp`,`user`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 --
index b4abdda..737f24d 100644 (file)
@@ -8,7 +8,7 @@
 #        and is automatically called by Auth.pm when needed.
 
 sub kohaversion {
-    return "3.00.00.016";
+    return "3.00.00.017";
 }
 
 1;
index 7f03115..599e0c6 100755 (executable)
@@ -504,6 +504,16 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }      
 
+$DBversion = "3.00.00.017";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {                                                                                    
+    $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
+       $dbh->do("ALTER TABLE action_logs ADD KEY  timestamp (timestamp,user)");
+       $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
+       $dbh->do("UPDATE action_logs SET action_id = if (@a, @a:=@a+1, @a:=1)");
+       $dbh->do("ALTER TABLE action_logs MODIFY action_id AUTO_INCREMENT PRIMARY KEY");
+       print "Upgrade to $DBversion done (added column to action_logs)\n";
+       SetVersion ($DBversion);
+}
 
 =item DropAllForeignKeys($table)