From 0f8731622efebcc3d747bfc867bf6180358d849a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 26 Jul 2023 11:54:49 -0400 Subject: [PATCH] Bug 28966: (QA Follow-up) Fix failing unit tests Test Plan: 1) prove t/db_dependent/TestBuilder.t 2) Note tests fail 3) Apply this patch 4) Run updatedatabase.pl 5) Update the schema files ( alias 'dbic' can be used in koha-testing-docker ) 6) prove t/db_dependent/TestBuilder.t 7) Tests now pass! --- Koha/Schema/Result/Item.pm | 12 +++---- Koha/Schema/Result/TmpHoldsqueue.pm | 31 ++++++++++++------- .../data/mysql/atomicupdate/bug_32966.pl | 18 +++++++++++ installer/data/mysql/kohastructure.sql | 1 + t/db_dependent/TestBuilder.t | 21 ++++++------- 5 files changed, 53 insertions(+), 30 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_32966.pl diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 980ea046c4..0e98aaf503 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -927,24 +927,24 @@ __PACKAGE__->might_have( { cascade_copy => 0, cascade_delete => 0 }, ); -=head2 tmp_holdsqueues +=head2 tmp_holdsqueue -Type: has_many +Type: might_have Related object: L =cut -__PACKAGE__->has_many( - "tmp_holdsqueues", +__PACKAGE__->might_have( + "tmp_holdsqueue", "Koha::Schema::Result::TmpHoldsqueue", { "foreign.itemnumber" => "self.itemnumber" }, { cascade_copy => 0, cascade_delete => 0 }, ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-05-12 18:18:47 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HMU2tnuIRypuatz/J5683A +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-26 15:16:46 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:77fdafpHCGzK6+An02hikA __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); diff --git a/Koha/Schema/Result/TmpHoldsqueue.pm b/Koha/Schema/Result/TmpHoldsqueue.pm index 2bf9ec46be..4b203c5219 100644 --- a/Koha/Schema/Result/TmpHoldsqueue.pm +++ b/Koha/Schema/Result/TmpHoldsqueue.pm @@ -33,7 +33,7 @@ __PACKAGE__->table("tmp_holdsqueue"); data_type: 'integer' is_foreign_key: 1 - is_nullable: 1 + is_nullable: 0 =head2 barcode @@ -123,7 +123,7 @@ __PACKAGE__->add_columns( "biblionumber", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "itemnumber", - { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "barcode", { data_type => "varchar", is_nullable => 1, size => 20 }, "surname", @@ -159,6 +159,18 @@ __PACKAGE__->add_columns( }, ); +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("itemnumber"); + =head1 RELATIONS =head2 biblionumber @@ -208,17 +220,12 @@ __PACKAGE__->belongs_to( "itemnumber", "Koha::Schema::Result::Item", { itemnumber => "itemnumber" }, - { - is_deferrable => 1, - join_type => "LEFT", - on_delete => "CASCADE", - on_update => "CASCADE", - }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-04 22:42:42 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RdIrLi+vbzj3ab/UP7e9pw +# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-26 15:16:46 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Va8u8f6X3nZxEJULOMF31A __PACKAGE__->add_columns( '+item_level_request' => { is_boolean => 1 } @@ -273,11 +280,11 @@ __PACKAGE__->belongs_to( ); sub koha_object_class { - 'Koha::HoldsQueueItem'; + 'Koha::Hold::HoldsQueueItem'; } sub koha_objects_class { - 'Koha::HoldsQueueItems'; + 'Koha::Hold::HoldsQueueItems'; } 1; diff --git a/installer/data/mysql/atomicupdate/bug_32966.pl b/installer/data/mysql/atomicupdate/bug_32966.pl new file mode 100755 index 0000000000..55a7db5827 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_32966.pl @@ -0,0 +1,18 @@ +use Modern::Perl; + +return { + bug_number => "28966", + description => "Holds queue view too slow to load for large numbers of holds", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + unless ( primary_key_exists( 'tmp_holdsqueue', 'itemnumber' ) ) { + $dbh->do( + q{ALTER TABLE tmp_holdsqueue ADD PRIMARY KEY (itemnumber)} + ); + } + + say $out "Set primary key for table 'tmp_holdsqueue' to 'itemnumber'"; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 270cca9f50..c1f800fe7f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -5885,6 +5885,7 @@ CREATE TABLE `tmp_holdsqueue` ( `notes` mediumtext DEFAULT NULL, `item_level_request` tinyint(4) NOT NULL DEFAULT 0, `timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date and time this entry as added/last updated', + PRIMARY KEY (`itemnumber`), KEY `tmp_holdsqueue_ibfk_1` (`itemnumber`), KEY `tmp_holdsqueue_ibfk_2` (`biblionumber`), KEY `tmp_holdsqueue_ibfk_3` (`borrowernumber`), diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index 1fa63d0ae1..9946df3174 100755 --- a/t/db_dependent/TestBuilder.t +++ b/t/db_dependent/TestBuilder.t @@ -285,7 +285,7 @@ subtest 'Test build with NULL values' => sub { subtest 'Tests for delete method' => sub { - plan tests => 12; + plan tests => 11; $schema->storage->txn_begin; @@ -304,23 +304,20 @@ subtest 'Tests for delete method' => sub { # Test delete in table without primary key (..) - is( $schema->source('TmpHoldsqueue')->primary_columns, 0, + is( $schema->source('AccountCreditTypesBranch')->primary_columns, 0, 'Table without primary key detected' ); - my $bibno = $builder->build_sample_biblio->biblionumber; - my $cnt1 = $schema->resultset('TmpHoldsqueue')->count; - # Insert a new record in TmpHoldsqueue with that biblionumber - my $val = { biblionumber => $bibno }; - my $rec = $builder->build({ source => 'TmpHoldsqueue', value => $val }); - my $cnt2 = $schema->resultset('TmpHoldsqueue')->count; + my $cnt1 = $schema->resultset('AccountCreditTypesBranch')->count; + # Insert a new record in AccountCreditTypesBranch with that biblionumber + my $rec = $builder->build({ source => 'AccountCreditTypesBranch' }); + my $cnt2 = $schema->resultset('AccountCreditTypesBranch')->count; is( defined($rec) && $cnt2 == $cnt1 + 1 , 1, 'Created a record' ); - is( $builder->delete({ source => 'TmpHoldsqueue', records => $rec }), + is( $builder->delete({ source => 'AccountCreditTypesBranch', records => $rec }), undef, 'delete returns undef' ); - is( $rec->{biblionumber}, $bibno, 'Hash value untouched' ); - is( $schema->resultset('TmpHoldsqueue')->count, $cnt2, + is( $schema->resultset('AccountCreditTypesBranch')->count, $cnt2, "Method did not delete record in table without PK" ); # Test delete with NULL values - $val = { branchcode => undef }; + my $val = { branchcode => undef }; is( $builder->delete({ source => 'Branch', records => $val }), 0, 'delete returns zero for an undef search with one key' ); $val = { module_bit => 1, #catalogue -- 2.30.2