View | Details | Raw Unified | Return to bug 7065
Collapse All | Expand All

(-)a/installer/data/mysql/kohastructure.sql (+4 lines)
Lines 1384-1389 CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r Link Here
1384
--
1384
--
1385
DROP TABLE IF EXISTS `old_reserves`;
1385
DROP TABLE IF EXISTS `old_reserves`;
1386
CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1386
CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1387
  `reservenumber` int(11) NOT NULL,
1387
  `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1388
  `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1388
  `reservedate` date default NULL, -- the date the hold was places
1389
  `reservedate` date default NULL, -- the date the hold was places
1389
  `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
1390
  `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
Lines 1400-1405 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1400
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1401
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1401
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1402
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1402
  `lowestPriority` tinyint(1) NOT NULL,
1403
  `lowestPriority` tinyint(1) NOT NULL,
1404
  PRIMARY KEY (`reservenumber`),
1403
  KEY `old_reserves_borrowernumber` (`borrowernumber`),
1405
  KEY `old_reserves_borrowernumber` (`borrowernumber`),
1404
  KEY `old_reserves_biblionumber` (`biblionumber`),
1406
  KEY `old_reserves_biblionumber` (`biblionumber`),
1405
  KEY `old_reserves_itemnumber` (`itemnumber`),
1407
  KEY `old_reserves_itemnumber` (`itemnumber`),
Lines 1559-1564 CREATE TABLE `reserveconstraints` ( Link Here
1559
1561
1560
DROP TABLE IF EXISTS `reserves`;
1562
DROP TABLE IF EXISTS `reserves`;
1561
CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1563
CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1564
  `reservenumber` int(11) NOT NULL AUTO_INCREMENT,
1562
  `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1565
  `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1563
  `reservedate` date default NULL, -- the date the hold was places
1566
  `reservedate` date default NULL, -- the date the hold was places
1564
  `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
1567
  `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
Lines 1575-1580 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1575
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1578
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1576
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1579
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1577
  `lowestPriority` tinyint(1) NOT NULL,
1580
  `lowestPriority` tinyint(1) NOT NULL,
1581
  PRIMARY KEY (`reservenumber`),
1578
  KEY priorityfoundidx (priority,found),
1582
  KEY priorityfoundidx (priority,found),
1579
  KEY `borrowernumber` (`borrowernumber`),
1583
  KEY `borrowernumber` (`borrowernumber`),
1580
  KEY `biblionumber` (`biblionumber`),
1584
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +50 lines)
Lines 4712-4717 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4712
    SetVersion($DBversion);
4712
    SetVersion($DBversion);
4713
}
4713
}
4714
4714
4715
$DBversion = "3.07.00.XXX";
4716
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4717
    $dbh->do("ALTER TABLE reserves ADD reservenumber INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
4718
    $dbh->do("ALTER TABLE old_reserves ADD reservenumber INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
4719
    
4720
    my ( $sth, $row );
4721
    
4722
    $sth = $dbh->prepare("SELECT MAX( reservenumber ) AS last_old_reservenumber FROM old_reserves");
4723
    $sth->execute();
4724
    $row = $sth->fetchrow_hashref();
4725
    my $last_old_reservenumber = $row->{'last_old_reservenumber'};
4726
    $sth->finish();
4727
4728
    $sth = $dbh->prepare("SELECT MAX( reservenumber ) AS last_reservenumber FROM reserves");
4729
    $sth->execute();
4730
    $row = $sth->fetchrow_hashref();
4731
    my $last_bad_reservenumber = $row->{'last_reservenumber'};
4732
    my $reserves_count = $last_bad_reservenumber;
4733
    $sth->finish();
4734
    
4735
    my $query = "UPDATE reserves SET reservenumber = ? WHERE reservenumber = ?";
4736
    my $update_sth = $dbh->prepare( $query );
4737
    
4738
    ## First, change all reservenumbers to new ones above the highest that was intially added.
4739
    ## That way, we can renumber them without the risk of using a duplicate reservenumber
4740
    my $new_reservenumber = $last_bad_reservenumber + 1;
4741
    $sth = $dbh->prepare("SELECT reservenumber FROM reserves");
4742
    $sth->execute();
4743
    while ( $row = $sth->fetchrow_hashref() ) {
4744
        $update_sth->execute( $new_reservenumber, $row->{'reservenumber'} );
4745
        $new_reservenumber++;
4746
    }
4747
4748
    ## First, change all reservenumbers to new ones above the highest that was intially added.
4749
    ## That way, we can renumber them without the risk of using a duplicate reservenumber
4750
    $new_reservenumber = $last_old_reservenumber + 1;
4751
    $sth = $dbh->prepare("SELECT reservenumber FROM reserves");
4752
    $sth->execute();
4753
    while ( $row = $sth->fetchrow_hashref() ) {
4754
        $update_sth->execute( $new_reservenumber, $row->{'reservenumber'} );
4755
        $new_reservenumber++;
4756
    }
4757
4758
    ## Drop the auto_increment from the old_reserves table.
4759
    $dbh->do("ALTER TABLE old_reserves CHANGE reservenumber reservenumber INT( 11 ) NOT NULL");
4760
4761
    print "Upgrade to $DBversion done (Added reservenumber to reserves and old_reserves tables)\n";
4762
    SetVersion($DBversion);
4763
}
4764
4715
=head1 FUNCTIONS
4765
=head1 FUNCTIONS
4716
4766
4717
=head2 DropAllForeignKeys($table)
4767
=head2 DropAllForeignKeys($table)
4718
- 

Return to bug 7065