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

(-)a/installer/data/mysql/kohastructure.sql (+4 lines)
Lines 1446-1451 CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r Link Here
1446
--
1446
--
1447
DROP TABLE IF EXISTS `old_reserves`;
1447
DROP TABLE IF EXISTS `old_reserves`;
1448
CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1448
CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1449
  `reserve_id` int(11) NOT NULL, -- primary key
1449
  `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1450
  `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1450
  `reservedate` date default NULL, -- the date the hold was places
1451
  `reservedate` date default NULL, -- the date the hold was places
1451
  `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
1452
  `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
Lines 1464-1469 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1464
  `lowestPriority` tinyint(1) NOT NULL,
1465
  `lowestPriority` tinyint(1) NOT NULL,
1465
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1466
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1466
  `suspend_until` DATETIME NULL DEFAULT NULL,
1467
  `suspend_until` DATETIME NULL DEFAULT NULL,
1468
  PRIMARY KEY (`reserve_id`),
1467
  KEY `old_reserves_borrowernumber` (`borrowernumber`),
1469
  KEY `old_reserves_borrowernumber` (`borrowernumber`),
1468
  KEY `old_reserves_biblionumber` (`biblionumber`),
1470
  KEY `old_reserves_biblionumber` (`biblionumber`),
1469
  KEY `old_reserves_itemnumber` (`itemnumber`),
1471
  KEY `old_reserves_itemnumber` (`itemnumber`),
Lines 1642-1647 CREATE TABLE `reserveconstraints` ( Link Here
1642
1644
1643
DROP TABLE IF EXISTS `reserves`;
1645
DROP TABLE IF EXISTS `reserves`;
1644
CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1646
CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1647
  `reserve_id` int(11) NOT NULL auto_increment, -- primary key
1645
  `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1648
  `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1646
  `reservedate` date default NULL, -- the date the hold was places
1649
  `reservedate` date default NULL, -- the date the hold was places
1647
  `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
1650
  `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
Lines 1660-1665 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1660
  `lowestPriority` tinyint(1) NOT NULL,
1663
  `lowestPriority` tinyint(1) NOT NULL,
1661
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1664
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1662
  `suspend_until` DATETIME NULL DEFAULT NULL,
1665
  `suspend_until` DATETIME NULL DEFAULT NULL,
1666
  PRIMARY KEY (`reserve_id`),
1663
  KEY priorityfoundidx (priority,found),
1667
  KEY priorityfoundidx (priority,found),
1664
  KEY `borrowernumber` (`borrowernumber`),
1668
  KEY `borrowernumber` (`borrowernumber`),
1665
  KEY `biblionumber` (`biblionumber`),
1669
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +63 lines)
Lines 5246-5251 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5246
    SetVersion($DBversion);
5246
    SetVersion($DBversion);
5247
}
5247
}
5248
5248
5249
$DBversion = "3.09.00.XXX";
5250
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5251
    $dbh->do('START TRANSACTION');
5252
    $dbh->do('CREATE TABLE tmp_reserves AS SELECT * FROM reserves LIMIT 0');
5253
    $dbh->do('ALTER TABLE tmp_reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
5254
    $dbh->do("
5255
        INSERT INTO tmp_reserves (
5256
          borrowernumber, reservedate, biblionumber,
5257
          constrainttype, branchcode, notificationdate,
5258
          reminderdate, cancellationdate, reservenotes,
5259
          priority, found, timestamp, itemnumber,
5260
          waitingdate, expirationdate, lowestPriority
5261
        ) SELECT
5262
          borrowernumber, reservedate, biblionumber,
5263
          constrainttype, branchcode, notificationdate,
5264
          reminderdate, cancellationdate, reservenotes,
5265
          priority, found, timestamp, itemnumber,
5266
          waitingdate, expirationdate, lowestPriority
5267
        FROM old_reserves ORDER BY reservedate
5268
    ");
5269
    $dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )');
5270
    $dbh->do('TRUNCATE old_reserves');
5271
    $dbh->do('ALTER TABLE old_reserves ADD reserve_id INT( 11 ) NOT NULL PRIMARY KEY FIRST');
5272
    $dbh->do('INSERT INTO old_reserves SELECT * FROM tmp_reserves WHERE reserve_id <= @ai');
5273
    $dbh->do("
5274
        INSERT INTO tmp_reserves (
5275
          borrowernumber, reservedate, biblionumber,
5276
          constrainttype, branchcode, notificationdate,
5277
          reminderdate, cancellationdate, reservenotes,
5278
          priority, found, timestamp, itemnumber,
5279
          waitingdate, expirationdate, lowestPriority
5280
        ) SELECT
5281
          borrowernumber, reservedate, biblionumber,
5282
          constrainttype, branchcode, notificationdate,
5283
          reminderdate, cancellationdate, reservenotes,
5284
          priority, found, timestamp, itemnumber,
5285
          waitingdate, expirationdate, lowestPriority
5286
        FROM reserves ORDER BY reservedate
5287
    ");
5288
    $dbh->do('TRUNCATE reserves');
5289
    $dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
5290
    $dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai');
5291
    $dbh->do('DROP TABLE tmp_reserves');
5292
    $dbh->do('COMMIT');
5293
5294
    my $sth = $dbh->prepare("
5295
        SELECT COUNT( * ) AS count
5296
        FROM information_schema.COLUMNS
5297
        WHERE COLUMN_NAME =  'reserve_id'
5298
        AND (
5299
          TABLE_NAME LIKE  'reserves'
5300
          OR
5301
          TABLE_NAME LIKE  'old_reserves'
5302
        )
5303
    ");
5304
    $sth->execute();
5305
    my $row = $sth->fetchrow_hashref();
5306
    die("Failed to add reserve_id to reserves tables, please refresh the page to try again.") unless ( $row->{'count'} );
5307
5308
    print "Upgrade to $DBversion done (add reserve_id to reserves & old_reserves tables)\n";
5309
    SetVersion($DBversion);
5310
}
5311
5249
=head1 FUNCTIONS
5312
=head1 FUNCTIONS
5250
5313
5251
=head2 TableExists($table)
5314
=head2 TableExists($table)
5252
- 

Return to bug 7065