From 224718b3adee28d33999379b0ebab1092ae88169 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 3 Jan 2019 18:56:14 +0000 Subject: [PATCH] Bug 19066: DBRev 18.12.00.004 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- Koha/Schema/Result/Accountline.pm | 33 +++++++++++++++++-- Koha/Schema/Result/Branch.pm | 19 +++++++++-- ...bug_19066_add_accountlines_branchcode.perl | 12 ------- installer/data/mysql/updatedatabase.pl | 10 ++++++ 5 files changed, 59 insertions(+), 17 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_19066_add_accountlines_branchcode.perl diff --git a/Koha.pm b/Koha.pm index a9a56fd092..ed99a76a0b 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.003"; +$VERSION = "18.12.00.004"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Accountline.pm b/Koha/Schema/Result/Accountline.pm index 641b632ee7..b5e220a90e 100644 --- a/Koha/Schema/Result/Accountline.pm +++ b/Koha/Schema/Result/Accountline.pm @@ -110,6 +110,13 @@ __PACKAGE__->table("accountlines"); data_type: 'integer' is_nullable: 1 +=head2 branchcode + + data_type: 'varchar' + is_foreign_key: 1 + is_nullable: 1 + size: 10 + =cut __PACKAGE__->add_columns( @@ -148,6 +155,8 @@ __PACKAGE__->add_columns( { data_type => "mediumtext", is_nullable => 1 }, "manager_id", { data_type => "integer", is_nullable => 1 }, + "branchcode", + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, ); =head1 PRIMARY KEY @@ -214,6 +223,26 @@ __PACKAGE__->belongs_to( }, ); +=head2 branchcode + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "branchcode", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + =head2 itemnumber Type: belongs_to @@ -235,8 +264,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-12-19 16:19:16 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kvBIJshNRsm/HYJBbhm0IA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-01-03 16:10:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BO7iSB+QzoJNuZ8Uttba6A sub koha_objects_class { 'Koha::Account::Lines'; diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm index 13fe183742..b894c54dc7 100644 --- a/Koha/Schema/Result/Branch.pm +++ b/Koha/Schema/Result/Branch.pm @@ -211,6 +211,21 @@ __PACKAGE__->set_primary_key("branchcode"); =head1 RELATIONS +=head2 accountlines + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "accountlines", + "Koha::Schema::Result::Accountline", + { "foreign.branchcode" => "self.branchcode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 aqbaskets Type: has_many @@ -662,8 +677,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-09 15:50:42 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0yMUX1UukdV7eMol06JXTQ +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-01-03 16:10:04 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:WyXH3sMlyuJIx0fd31RswA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_19066_add_accountlines_branchcode.perl b/installer/data/mysql/atomicupdate/bug_19066_add_accountlines_branchcode.perl deleted file mode 100644 index 62bbd550c1..0000000000 --- a/installer/data/mysql/atomicupdate/bug_19066_add_accountlines_branchcode.perl +++ /dev/null @@ -1,12 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - if( !column_exists( 'accountlines', 'branchcode' ) ) { - $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id"); - $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT accountlines_ibfk_branches FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE SET NULL ON UPDATE CASCADE"); - } - - # Always end with this (adjust the bug info) - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 19066 - Add branchcode to accountlines)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 6e9e76497d..92c8fc1c00 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -17205,6 +17205,16 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 22024 - Add missing splitting rule definitions)\n"; } +$DBversion = '18.12.00.004'; +if( CheckVersion( $DBversion ) ) { + if( !column_exists( 'accountlines', 'branchcode' ) ) { + $dbh->do("ALTER TABLE accountlines ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER manager_id"); + $dbh->do("ALTER TABLE accountlines ADD CONSTRAINT accountlines_ibfk_branches FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE SET NULL ON UPDATE CASCADE"); + } + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 19066 - Add branchcode to accountlines)\n"; +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.20.1