From 2c6d39452af2364463b509d7d18526714bc17b3f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 15 Feb 2019 13:17:45 +0000 Subject: [PATCH] Bug 13515: DBRev 18.12.00.014 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Borrower.pm | 19 ++++++++++++++-- Koha/Schema/Result/Message.pm | 22 ++++++++++++++++--- .../data/mysql/atomicupdate/bug_13515.perl | 20 ----------------- installer/data/mysql/updatedatabase.pl | 18 +++++++++++++++ 5 files changed, 55 insertions(+), 26 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_13515.perl diff --git a/Koha.pm b/Koha.pm index 129c33a044..38d12d08e2 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.013"; +$VERSION = "18.12.00.014"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index 8e4580f7e0..6c6fd7eaa8 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -1115,6 +1115,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 messages_borrowernumbers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "messages_borrowernumbers", + "Koha::Schema::Result::Message", + { "foreign.borrowernumber" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 old_issues Type: has_many @@ -1431,8 +1446,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-27 13:16:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:c3Tb59Kku0Hh+tsVV5eCDg +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-02-15 13:15:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:NhuG8jv9ut+qIIm3vGHsrQ __PACKAGE__->belongs_to( "guarantor", diff --git a/Koha/Schema/Result/Message.pm b/Koha/Schema/Result/Message.pm index 9fd862eee6..2c24dec1bb 100644 --- a/Koha/Schema/Result/Message.pm +++ b/Koha/Schema/Result/Message.pm @@ -32,6 +32,7 @@ __PACKAGE__->table("messages"); =head2 borrowernumber data_type: 'integer' + is_foreign_key: 1 is_nullable: 0 =head2 branchcode @@ -70,7 +71,7 @@ __PACKAGE__->add_columns( "message_id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "borrowernumber", - { data_type => "integer", is_nullable => 0 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "branchcode", { data_type => "varchar", is_nullable => 1, size => 10 }, "message_type", @@ -102,6 +103,21 @@ __PACKAGE__->set_primary_key("message_id"); =head1 RELATIONS +=head2 borrowernumber + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "borrowernumber", + "Koha::Schema::Result::Borrower", + { borrowernumber => "borrowernumber" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + =head2 manager Type: belongs_to @@ -123,8 +139,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:cNf9ogl9bN+0BC63dS1rmA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-02-15 13:15:09 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kYM+0CFPm/wdNp7EosdlRw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_13515.perl b/installer/data/mysql/atomicupdate/bug_13515.perl deleted file mode 100644 index 7a97061fba..0000000000 --- a/installer/data/mysql/atomicupdate/bug_13515.perl +++ /dev/null @@ -1,20 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - unless( foreign_key_exists( 'messages', 'messages_borrowernumber' ) ) { - $dbh->do(q| - DELETE m FROM messages m - LEFT JOIN borrowers b ON m.borrowernumber=b.borrowernumber - WHERE b.borrowernumber IS NULL - |); - - $dbh->do(q| - ALTER TABLE messages - ADD CONSTRAINT messages_borrowernumber - FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE - |); - } - - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 13515 - Add a FOREIGN KEY constaint on messages.borrowernumber)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 7cea28a8fc..cb95c409b2 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17330,6 +17330,24 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 22198 - Add ghranular permission setting for Mana KB)\n"; } +$DBversion = '18.12.00.014'; +if( CheckVersion( $DBversion ) ) { + unless( foreign_key_exists( 'messages', 'messages_borrowernumber' ) ) { + $dbh->do(q| + DELETE m FROM messages m + LEFT JOIN borrowers b ON m.borrowernumber=b.borrowernumber + WHERE b.borrowernumber IS NULL + |); + $dbh->do(q| + ALTER TABLE messages + ADD CONSTRAINT messages_borrowernumber + FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE + |); + } + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 13515 - Add a FOREIGN KEY constaint on messages.borrowernumber)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5