From f8c20ac4c91f22017093a2d8ed0dbb8b0a3738bc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 22 Mar 2019 20:04:33 +0000 Subject: [PATCH] Bug 22008: DBRev 18.12.00.031 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Accountline.pm | 29 ++++++++++++++++--- Koha/Schema/Result/Borrower.pm | 19 ++++++++++-- .../data/mysql/atomicupdate/bug_22008.perl | 19 ------------ installer/data/mysql/updatedatabase.pl | 20 +++++++++++++ 5 files changed, 63 insertions(+), 26 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_22008.perl diff --git a/Koha.pm b/Koha.pm index df5ad3804f..b37e7d31ea 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.030"; +$VERSION = "18.12.00.031"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Accountline.pm b/Koha/Schema/Result/Accountline.pm index 22416040fd..9b4505ed0f 100644 --- a/Koha/Schema/Result/Accountline.pm +++ b/Koha/Schema/Result/Accountline.pm @@ -102,6 +102,7 @@ __PACKAGE__->table("accountlines"); =head2 manager_id data_type: 'integer' + is_foreign_key: 1 is_nullable: 1 =head2 branchcode @@ -146,7 +147,7 @@ __PACKAGE__->add_columns( "note", { data_type => "mediumtext", is_nullable => 1 }, "manager_id", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "branchcode", { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, ); @@ -251,13 +252,33 @@ __PACKAGE__->belongs_to( is_deferrable => 1, join_type => "LEFT", on_delete => "SET NULL", - on_update => "SET NULL", + on_update => "CASCADE", + }, +); + +=head2 manager + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "manager", + "Koha::Schema::Result::Borrower", + { borrowernumber => "manager_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", }, ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-21 19:22:42 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hUtKezIBauLDzkRIq5ifTQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2019-03-22 20:06:37 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Op6tRrWF4pGrLcunNiXO+g sub koha_objects_class { 'Koha::Account::Lines'; diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm index a9e9a5c216..0c439e90b6 100644 --- a/Koha/Schema/Result/Borrower.pm +++ b/Koha/Schema/Result/Borrower.pm @@ -710,6 +710,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 accountlines_managers + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "accountlines_managers", + "Koha::Schema::Result::Accountline", + { "foreign.manager_id" => "self.borrowernumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 api_keys Type: has_many @@ -1506,8 +1521,8 @@ Composing rels: L -> ordernumber __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber"); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-03-11 12:56:41 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:F/j4bsmnxc2Cja5DKfMseQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2019-03-22 20:06:37 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dbRPH4TDrnUkzbJdgM5XcQ __PACKAGE__->belongs_to( "guarantor", diff --git a/installer/data/mysql/atomicupdate/bug_22008.perl b/installer/data/mysql/atomicupdate/bug_22008.perl deleted file mode 100644 index 8a398bb25d..0000000000 --- a/installer/data/mysql/atomicupdate/bug_22008.perl +++ /dev/null @@ -1,19 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - # Add constraint for manager_id - unless( foreign_key_exists( 'accountlines', 'accountlines_ibfk_borrowers_2' ) ) { - $dbh->do("ALTER TABLE accountlines CHANGE COLUMN manager_id manager_id INT(11) NULL DEFAULT NULL"); - $dbh->do("UPDATE accountlines a LEFT JOIN borrowers b ON ( a.manager_id = b.borrowernumber) SET a.manager_id = NULL WHERE b.borrowernumber IS NULL"); - $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE"); - } - - # Rename accountlines_ibfk_2 to accountlines_ibfk_items - if ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_2' ) && !foreign_key_exists( 'accountlines', 'accountlines_ibfk_items' ) ) { - $dbh->do("ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_2"); - $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE"); - } - - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 22008 - Add missing constraints for accountlines.manager_id)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 527c5cedb0..ab2711ce46 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17771,6 +17771,26 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 21683 - Remove accountlines.accountno and statistics.proccode fields)\n"; } +$DBversion = '18.12.00.031'; +if( CheckVersion( $DBversion ) ) { + + # Add constraint for manager_id + unless( foreign_key_exists( 'accountlines', 'accountlines_ibfk_borrowers_2' ) ) { + $dbh->do("ALTER TABLE accountlines CHANGE COLUMN manager_id manager_id INT(11) NULL DEFAULT NULL"); + $dbh->do("UPDATE accountlines a LEFT JOIN borrowers b ON ( a.manager_id = b.borrowernumber) SET a.manager_id = NULL WHERE b.borrowernumber IS NULL"); + $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE"); + } + + # Rename accountlines_ibfk_2 to accountlines_ibfk_items + if ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_2' ) && !foreign_key_exists( 'accountlines', 'accountlines_ibfk_items' ) ) { + $dbh->do("ALTER TABLE accountlines DROP FOREIGN KEY accountlines_ibfk_2"); + $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE"); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 22008 - Add missing constraints for accountlines.manager_id)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.20.1