From 542ee0a453bdbfc9cb524e5e8723fa37e4eb9da0 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Fri, 20 Feb 2015 19:31:39 +0200 Subject: [PATCH] Bug 13743 - Primary key for issues-table Each table must have a primary key. This makes extending issues-related functionality much easier. TEST PLAN: 1. Check-out Items for you. 2. Check-in Items from you. 3. Check-out using the SIP2-server. 4. Check-in using the SIP2-server. --- Koha/Schema/Result/Issue.pm | 29 +++++++++++++++++------------ installer/data/mysql/kohastructure.sql | 4 ++++ installer/data/mysql/updatedatabase.pl | 8 ++++++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Koha/Schema/Result/Issue.pm b/Koha/Schema/Result/Issue.pm index 5ec687e..74c1f00 100644 --- a/Koha/Schema/Result/Issue.pm +++ b/Koha/Schema/Result/Issue.pm @@ -1,21 +1,17 @@ -use utf8; package Koha::Schema::Result::Issue; # Created by DBIx::Class::Schema::Loader # DO NOT MODIFY THE FIRST PART OF THIS FILE -=head1 NAME - -Koha::Schema::Result::Issue - -=cut - use strict; use warnings; use base 'DBIx::Class::Core'; -=head1 TABLE: C + +=head1 NAME + +Koha::Schema::Result::Issue =cut @@ -23,6 +19,12 @@ __PACKAGE__->table("issues"); =head1 ACCESSORS +=head2 issueid + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + =head2 borrowernumber data_type: 'integer' @@ -104,6 +106,8 @@ __PACKAGE__->table("issues"); =cut __PACKAGE__->add_columns( + "issueid", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "borrowernumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "itemnumber", @@ -152,6 +156,7 @@ __PACKAGE__->add_columns( "onsite_checkout", { data_type => "integer", default_value => 0, is_nullable => 0 }, ); +__PACKAGE__->set_primary_key("issueid"); =head1 RELATIONS @@ -170,7 +175,7 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, join_type => "LEFT", - on_delete => "RESTRICT", + on_delete => "CASCADE", on_update => "CASCADE", }, ); @@ -190,14 +195,14 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, join_type => "LEFT", - on_delete => "RESTRICT", + on_delete => "CASCADE", on_update => "CASCADE", }, ); -# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-11-03 10:40:55 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7Y+5IerDnajn5GLwAY5thg +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2015-03-20 18:56:58 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YErqTROKWfByx78epaGbDw __PACKAGE__->belongs_to( "borrower", diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index cd83f99..c0ccaf2 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1140,6 +1140,7 @@ CREATE TABLE `import_items` ( DROP TABLE IF EXISTS `issues`; CREATE TABLE `issues` ( -- information related to check outs or issues + `issueid` int(12) NOT NULL auto_increment, `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) @@ -1153,6 +1154,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues `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 (`issueid`), KEY `issuesborridx` (`borrowernumber`), KEY `itemnumber_idx` (`itemnumber`), KEY `branchcode_idx` (`branchcode`), @@ -1614,6 +1616,7 @@ CREATE TABLE `oai_sets_biblios` ( DROP TABLE IF EXISTS `old_issues`; CREATE TABLE `old_issues` ( -- lists items that were checked out and have been returned + `issueid` int(12) NOT NULL auto_increment, `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) @@ -1627,6 +1630,7 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r `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 (`issueid`), KEY `old_issuesborridx` (`borrowernumber`), KEY `old_issuesitemidx` (`itemnumber`), KEY `branchcode_idx` (`branchcode`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index ad8ec97..d4a429a 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6661,6 +6661,14 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.19.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("ALTER TABLE issues ADD COLUMN issueid int(12) NOT NULL auto_increment FIRST, ADD CONSTRAINT PRIMARY KEY (issueid);"); + $dbh->do("ALTER TABLE old_issues ADD COLUMN issueid int(12) NOT NULL auto_increment FIRST, ADD CONSTRAINT PRIMARY KEY (issueid);"); + print "Upgrade to $DBversion done (Bug 13743 - Primary key for issues-table)\n"; + SetVersion ($DBversion); +} + $DBversion = "3.11.00.108"; if ( CheckVersion($DBversion) ) { $dbh->do("ALTER TABLE action_logs CHANGE timestamp timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"); -- 1.7.9.5