DROP TABLE IF EXISTS `issues`;
CREATE TABLE `issues` ( -- information related to check outs or issues
+ `issue_id` int(11) NOT NULL AUTO_INCREMENT, -- primary key for issues table
`borrowernumber` int(11), -- foreign key, linking this to the borrowers table for the patron this item was checked out to
`itemnumber` int(11), -- foreign key, linking this to the items table for the item that was checked out
`date_due` datetime default NULL, -- datetime the item is due (yyyy-mm-dd hh:mm::ss)
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched
`issuedate` datetime default NULL, -- date the item was checked out or issued
`onsite_checkout` int(1) NOT NULL default 0, -- in house use flag
+ PRIMARY KEY (`issue_id`),
KEY `issuesborridx` (`borrowernumber`),
KEY `itemnumber_idx` (`itemnumber`),
KEY `branchcode_idx` (`branchcode`),
DROP TABLE IF EXISTS `old_issues`;
CREATE TABLE `old_issues` ( -- lists items that were checked out and have been returned
+ `issue_id` int(11) NOT NULL, -- primary key for issues table
`borrowernumber` int(11) default NULL, -- foreign key, linking this to the borrowers table for the patron this item was checked out to
`itemnumber` int(11) default NULL, -- foreign key, linking this to the items table for the item that was checked out
`date_due` datetime default NULL, -- date the item is due (yyyy-mm-dd)
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this record was last touched
`issuedate` datetime default NULL, -- date the item was checked out or issued
`onsite_checkout` int(1) NOT NULL default 0, -- in house use flag
+ PRIMARY KEY (`issue_id`),
KEY `old_issuesborridx` (`borrowernumber`),
KEY `old_issuesitemidx` (`itemnumber`),
KEY `branchcode_idx` (`branchcode`),
use C4::Context;
use C4::Installer;
use C4::Dates;
+use Koha::Database;
use MARC::Record;
use MARC::File::XML ( BinaryEncoding => 'utf8' );
print "Upgrade to $DBversion done (3.2.0 general release)\n";
SetVersion ($DBversion);
}
-
# This is the point where 3.2.x and master diverged, we can use $original_version to make sure we don't
+
# apply updates that have already been done
$DBversion = "3.03.00.001";
SetVersion($DBversion);
}
+
$DBversion = '3.19.00.017';
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
# First create the column
my $rv = $installer->load_sql( $update_dir . $file ) ? 0 : 1;
}
+$DBversion = "XXX";
+if(CheckVersion($DBversion)) {
+ $dbh->do(q{
+ ALTER TABLE old_issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
+ });
+
+ $dbh->do(q{
+ ALTER TABLE issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
+ });
+
+ $dbh->do(q{
+ UPDATE issues SET issue_id = issue_id + ( SELECT COUNT(*) FROM old_issues ) ORDER BY issue_id DESC
+ });
+
+ my $schema = Koha::Database->new()->schema();
+ my $max_issue_id = $schema->resultset('Issue')->get_column('issue_id')->max();
+ $max_issue_id ||= $schema->resultset('OldIssue')->get_column('issue_id')->max();
+ $max_issue_id ||= 0;
+ $max_issue_id++;
+ $dbh->do(qq{
+ ALTER TABLE issues AUTO_INCREMENT = $max_issue_id}
+ );
+
+ print "Upgrade to $DBversion done (Bug 13790 - Add unique id issue_id to issues and oldissues tables)\n";
+ SetVersion($DBversion);
+
+}
+
=head1 FUNCTIONS
=head2 TableExists($table)