From b90bbc125969dc0048dde2ec37531a6ef6cd2b36 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 14 May 2019 18:15:54 +0000 Subject: [PATCH] Bug 22899: DBRev 18.12.00.075 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Item.pm | 19 ++++++++++-- Koha/Schema/Result/TmpHoldsqueue.pm | 29 +++++++++++++++++-- ...add_items_constraint_to_tmpholdsqueue.perl | 18 ------------ installer/data/mysql/updatedatabase.pl | 19 ++++++++++++ 5 files changed, 63 insertions(+), 24 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_22899_add_items_constraint_to_tmpholdsqueue.perl diff --git a/Koha.pm b/Koha.pm index 8bb2e647bf..80d0a8b0c6 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "18.12.00.074"; +$VERSION = "18.12.00.075"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 106ebd2edb..9d5743f5c2 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -701,9 +701,24 @@ __PACKAGE__->might_have( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 tmp_holdsqueues -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-09 15:50:42 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PQvA8qoxvTe4In5/oa5WIQ +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "tmp_holdsqueues", + "Koha::Schema::Result::TmpHoldsqueue", + { "foreign.itemnumber" => "self.itemnumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-05-14 18:14:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wDXcErUYqg0aoQkzz3P5vg __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); diff --git a/Koha/Schema/Result/TmpHoldsqueue.pm b/Koha/Schema/Result/TmpHoldsqueue.pm index 6a8c76e4d6..bb65f43dac 100644 --- a/Koha/Schema/Result/TmpHoldsqueue.pm +++ b/Koha/Schema/Result/TmpHoldsqueue.pm @@ -31,6 +31,7 @@ __PACKAGE__->table("tmp_holdsqueue"); =head2 itemnumber data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 barcode @@ -111,7 +112,7 @@ __PACKAGE__->add_columns( "biblionumber", { data_type => "integer", is_nullable => 1 }, "itemnumber", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "barcode", { data_type => "varchar", is_nullable => 1, size => 20 }, "surname", @@ -140,9 +141,31 @@ __PACKAGE__->add_columns( { data_type => "tinyint", default_value => 0, is_nullable => 0 }, ); +=head1 RELATIONS + +=head2 itemnumber + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "itemnumber", + "Koha::Schema::Result::Item", + { itemnumber => "itemnumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1Wa4h3u3FePOhGPD8SHEWg +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-05-14 18:14:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tzgAgf+OVO+IncaTr7SZuQ # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_22899_add_items_constraint_to_tmpholdsqueue.perl b/installer/data/mysql/atomicupdate/bug_22899_add_items_constraint_to_tmpholdsqueue.perl deleted file mode 100644 index 79e8f41646..0000000000 --- a/installer/data/mysql/atomicupdate/bug_22899_add_items_constraint_to_tmpholdsqueue.perl +++ /dev/null @@ -1,18 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - # you can use $dbh here like: - unless ( foreign_key_exists( 'tmp_holdsqueue', 'tmp_holdsqueue_ibfk_1' ) ) { - $dbh->do(q{ - DELETE t FROM tmp_holdsqueue t - LEFT JOIN items i ON t.itemnumber=i.itemnumber - WHERE i.itemnumber IS NULL - }); - $dbh->do(q{ - ALTER TABLE tmp_holdsqueue - ADD CONSTRAINT `tmp_holdsqueue_ibfk_1` FOREIGN KEY (`itemnumber`) - REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE - }); - } - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug XXXXX - Add items constraint to tmp_holdsqueue)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index da85fdc989..e6cba430a0 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -18657,6 +18657,25 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 21411 - Add keyboard_shortcuts table)\n"; } +$DBversion = '18.12.00.075'; +if( CheckVersion( $DBversion ) ) { + # you can use $dbh here like: + unless ( foreign_key_exists( 'tmp_holdsqueue', 'tmp_holdsqueue_ibfk_1' ) ) { + $dbh->do(q{ + DELETE t FROM tmp_holdsqueue t + LEFT JOIN items i ON t.itemnumber=i.itemnumber + WHERE i.itemnumber IS NULL + }); + $dbh->do(q{ + ALTER TABLE tmp_holdsqueue + ADD CONSTRAINT `tmp_holdsqueue_ibfk_1` FOREIGN KEY (`itemnumber`) + REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE + }); + } + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 22899 - Add items constraint to tmp_holdsqueue)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5