CHANGE TO PREVIOUS .046 DATABASE UPDATE
authorRyan Higgins <rch@liblime.com>
Tue, 8 Jan 2008 21:17:00 +0000 (15:17 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 8 Jan 2008 22:13:17 +0000 (16:13 -0600)
This commit changes .046 updatedatebase , where itemnumber was changed
to int and keyed on items table.  As there is code in serials module that
uses itemnumber (text) as a list of itemnumbers, this change would cause data
loss if that field had multiple items in it.
Instead, we add a new table to link serial and items tables, so that
(1) we can have many items per serial issue, and
(2) staged upgrades that use the serial.itemnumber (text) list won't be affected.
Further commits will make use of the serialitems linking table.

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Items.pm
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl

index f263629..975e0c8 100644 (file)
@@ -1586,7 +1586,9 @@ Perform the actual insert into the C<items> table.
 sub _koha_new_item {
     my ( $dbh, $item, $barcode ) = @_;
     my $error;
-
+use Data::Dumper;
+warn Dumper($item);
+warn $barcode;
     my $query =
            "INSERT INTO items SET
             biblionumber        = ?,
@@ -1620,7 +1622,7 @@ sub _koha_new_item {
             ccode               = ?,
             itype               = ?,
             materials           = ?,
-            uri                 = ?,
+                       uri                 = ?
           ";
     my $sth = $dbh->prepare($query);
    $sth->execute(
index 741122c..26a3272 100644 (file)
@@ -1535,11 +1535,10 @@ CREATE TABLE `serial` (
   `planneddate` date default NULL,
   `notes` text,
   `publisheddate` date default NULL,
-  `itemnumber` int(11) default NULL,
+  `itemnumber` text default NULL,
   `claimdate` date default NULL,
   `routingnotes` text,
   PRIMARY KEY  (`serialid`),
-  KEY serialitem (`itemnumber`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 --
@@ -1885,6 +1884,13 @@ CREATE TABLE language_script_mapping (
         KEY `language_subtag` (`language_subtag`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+DROP TABLE IF EXISTS serialitems;
+CREATE TABLE serialitem (
+        serialid int(11) NOT NULL,
+        itemnumber int(11) NOT NULL,
+        UNIQUE KEY `serialididx` (`serialid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
index 11ea46f..47a1ce3 100755 (executable)
@@ -932,10 +932,11 @@ VALUES( 'he', 'Hebr')");
 
 $DBversion = "3.00.00.046";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("ALTER TABLE `serial` CHANGE `itemnumber` `itemnumber` int(11) default NULL");
     $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default NULL , 
                 CHANGE `weeklength` `weeklength` int(11) default NULL");
-    $dbh->do("ALTER TABLE `serial` ADD UNIQUE KEY `serialitemidx` (`itemnumber`)");
+    $dbh->do("ALTER TABLE `serial` ADD UNIQUE KEY `serialitemidx` (`serialitem`)");
+    $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+    $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
        print "Upgrade to $DBversion done (Update serial table, add index on itemnumber. )\n";
     SetVersion ($DBversion);
 }