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

(-)a/installer/data/mysql/kohastructure.sql (+4 lines)
Lines 1448-1453 CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r Link Here
1448
--
1448
--
1449
DROP TABLE IF EXISTS `old_reserves`;
1449
DROP TABLE IF EXISTS `old_reserves`;
1450
CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1450
CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have been completed (either filled or cancelled)
1451
  `reserve_id` int(11) NOT NULL, -- primary key
1451
  `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1452
  `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table defining which patron this hold is for
1452
  `reservedate` date default NULL, -- the date the hold was places
1453
  `reservedate` date default NULL, -- the date the hold was places
1453
  `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
1454
  `biblionumber` int(11) default NULL, -- foreign key from the biblio table defining which bib record this hold is on
Lines 1466-1471 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1466
  `lowestPriority` tinyint(1) NOT NULL,
1467
  `lowestPriority` tinyint(1) NOT NULL,
1467
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1468
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1468
  `suspend_until` DATETIME NULL DEFAULT NULL,
1469
  `suspend_until` DATETIME NULL DEFAULT NULL,
1470
  PRIMARY KEY (`reserve_id`),
1469
  KEY `old_reserves_borrowernumber` (`borrowernumber`),
1471
  KEY `old_reserves_borrowernumber` (`borrowernumber`),
1470
  KEY `old_reserves_biblionumber` (`biblionumber`),
1472
  KEY `old_reserves_biblionumber` (`biblionumber`),
1471
  KEY `old_reserves_itemnumber` (`itemnumber`),
1473
  KEY `old_reserves_itemnumber` (`itemnumber`),
Lines 1644-1649 CREATE TABLE `reserveconstraints` ( Link Here
1644
1646
1645
DROP TABLE IF EXISTS `reserves`;
1647
DROP TABLE IF EXISTS `reserves`;
1646
CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1648
CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha
1649
  `reserve_id` int(11) NOT NULL auto_increment, -- primary key
1647
  `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1650
  `borrowernumber` int(11) NOT NULL default 0, -- foreign key from the borrowers table defining which patron this hold is for
1648
  `reservedate` date default NULL, -- the date the hold was places
1651
  `reservedate` date default NULL, -- the date the hold was places
1649
  `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
1652
  `biblionumber` int(11) NOT NULL default 0, -- foreign key from the biblio table defining which bib record this hold is on
Lines 1662-1667 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1662
  `lowestPriority` tinyint(1) NOT NULL,
1665
  `lowestPriority` tinyint(1) NOT NULL,
1663
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1666
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1664
  `suspend_until` DATETIME NULL DEFAULT NULL,
1667
  `suspend_until` DATETIME NULL DEFAULT NULL,
1668
  PRIMARY KEY (`reserve_id`),
1665
  KEY priorityfoundidx (priority,found),
1669
  KEY priorityfoundidx (priority,found),
1666
  KEY `borrowernumber` (`borrowernumber`),
1670
  KEY `borrowernumber` (`borrowernumber`),
1667
  KEY `biblionumber` (`biblionumber`),
1671
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +63 lines)
Lines 5369-5374 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5369
    SetVersion($DBversion);
5369
    SetVersion($DBversion);
5370
}
5370
}
5371
5371
5372
$DBversion = "3.09.00.XXX";
5373
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5374
    $dbh->do('START TRANSACTION');
5375
    $dbh->do('CREATE TABLE tmp_reserves AS SELECT * FROM old_reserves LIMIT 0');
5376
    $dbh->do('ALTER TABLE tmp_reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
5377
    $dbh->do("
5378
        INSERT INTO tmp_reserves (
5379
          borrowernumber, reservedate, biblionumber,
5380
          constrainttype, branchcode, notificationdate,
5381
          reminderdate, cancellationdate, reservenotes,
5382
          priority, found, timestamp, itemnumber,
5383
          waitingdate, expirationdate, lowestPriority
5384
        ) SELECT
5385
          borrowernumber, reservedate, biblionumber,
5386
          constrainttype, branchcode, notificationdate,
5387
          reminderdate, cancellationdate, reservenotes,
5388
          priority, found, timestamp, itemnumber,
5389
          waitingdate, expirationdate, lowestPriority
5390
        FROM old_reserves ORDER BY reservedate
5391
    ");
5392
    $dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )');
5393
    $dbh->do('TRUNCATE old_reserves');
5394
    $dbh->do('ALTER TABLE old_reserves ADD reserve_id INT( 11 ) NOT NULL PRIMARY KEY FIRST');
5395
    $dbh->do('INSERT INTO old_reserves SELECT * FROM tmp_reserves WHERE reserve_id <= @ai');
5396
    $dbh->do("
5397
        INSERT INTO tmp_reserves (
5398
          borrowernumber, reservedate, biblionumber,
5399
          constrainttype, branchcode, notificationdate,
5400
          reminderdate, cancellationdate, reservenotes,
5401
          priority, found, timestamp, itemnumber,
5402
          waitingdate, expirationdate, lowestPriority
5403
        ) SELECT
5404
          borrowernumber, reservedate, biblionumber,
5405
          constrainttype, branchcode, notificationdate,
5406
          reminderdate, cancellationdate, reservenotes,
5407
          priority, found, timestamp, itemnumber,
5408
          waitingdate, expirationdate, lowestPriority
5409
        FROM reserves ORDER BY reservedate
5410
    ");
5411
    $dbh->do('TRUNCATE reserves');
5412
    $dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
5413
    $dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai');
5414
    $dbh->do('DROP TABLE tmp_reserves');
5415
    $dbh->do('COMMIT');
5416
5417
    my $sth = $dbh->prepare("
5418
        SELECT COUNT( * ) AS count
5419
        FROM information_schema.COLUMNS
5420
        WHERE COLUMN_NAME =  'reserve_id'
5421
        AND (
5422
          TABLE_NAME LIKE  'reserves'
5423
          OR
5424
          TABLE_NAME LIKE  'old_reserves'
5425
        )
5426
    ");
5427
    $sth->execute();
5428
    my $row = $sth->fetchrow_hashref();
5429
    die("Failed to add reserve_id to reserves tables, please refresh the page to try again.") unless ( $row->{'count'} );
5430
5431
    print "Upgrade to $DBversion done (add reserve_id to reserves & old_reserves tables)\n";
5432
    SetVersion($DBversion);
5433
}
5434
5372
5435
5373
=head1 FUNCTIONS
5436
=head1 FUNCTIONS
5374
5437
5375
- 

Return to bug 7065