From 269bbbf2b670f2985febfa14554cd8a6d5b03620 Mon Sep 17 00:00:00 2001 From: Joy Nelson Date: Fri, 7 Feb 2020 23:11:45 +0000 Subject: [PATCH] Bug 24289: DBRev 19.11.02.003 Signed-off-by: Joy Nelson --- Koha.pm | 2 +- Koha/Schema/Result/Branch.pm | 34 +++++++++++++++++++++++-- Koha/Schema/Result/RepeatableHoliday.pm | 25 +++++++++++++++--- Koha/Schema/Result/SpecialHoliday.pm | 25 +++++++++++++++--- installer/data/mysql/updatedatabase.pl | 33 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 11 deletions(-) diff --git a/Koha.pm b/Koha.pm index ba889b912e..9160defb1a 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 = "19.11.02.002"; +$VERSION = "19.11.02.003"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm index 73b50e581b..d6ef74c38d 100644 --- a/Koha/Schema/Result/Branch.pm +++ b/Koha/Schema/Result/Branch.pm @@ -631,6 +631,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 repeatable_holidays + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "repeatable_holidays", + "Koha::Schema::Result::RepeatableHoliday", + { "foreign.branchcode" => "self.branchcode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 reserves Type: has_many @@ -646,6 +661,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 special_holidays + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "special_holidays", + "Koha::Schema::Result::SpecialHoliday", + { "foreign.branchcode" => "self.branchcode" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 stockrotationstages Type: has_many @@ -707,8 +737,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-14 09:59:52 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vWDJAm3K2jiyRS3htyip6A +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-02-07 23:10:36 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:8MMgxmWm5R7gR6DCh7DftQ __PACKAGE__->add_columns( '+pickup_location' => { is_boolean => 1 } diff --git a/Koha/Schema/Result/RepeatableHoliday.pm b/Koha/Schema/Result/RepeatableHoliday.pm index d1185c4fe8..b15cb725e7 100644 --- a/Koha/Schema/Result/RepeatableHoliday.pm +++ b/Koha/Schema/Result/RepeatableHoliday.pm @@ -32,7 +32,7 @@ __PACKAGE__->table("repeatable_holidays"); =head2 branchcode data_type: 'varchar' - default_value: (empty string) + is_foreign_key: 1 is_nullable: 0 size: 10 @@ -69,7 +69,7 @@ __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "branchcode", - { data_type => "varchar", default_value => "", is_nullable => 0, size => 10 }, + { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 10 }, "weekday", { data_type => "smallint", is_nullable => 1 }, "day", @@ -94,9 +94,26 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 RELATIONS + +=head2 branchcode + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "branchcode", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { is_deferrable => 1, 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:tp+p/e8mXWJv33yYXNMoww +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-02-07 23:10:36 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/WSWuhjk3b3PlmtuMSygWw # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/SpecialHoliday.pm b/Koha/Schema/Result/SpecialHoliday.pm index 29ff8bb0e1..f539be2c76 100644 --- a/Koha/Schema/Result/SpecialHoliday.pm +++ b/Koha/Schema/Result/SpecialHoliday.pm @@ -32,7 +32,7 @@ __PACKAGE__->table("special_holidays"); =head2 branchcode data_type: 'varchar' - default_value: (empty string) + is_foreign_key: 1 is_nullable: 0 size: 10 @@ -78,7 +78,7 @@ __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, "branchcode", - { data_type => "varchar", default_value => "", is_nullable => 0, size => 10 }, + { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 10 }, "day", { data_type => "smallint", default_value => 0, is_nullable => 0 }, "month", @@ -105,9 +105,26 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); +=head1 RELATIONS + +=head2 branchcode + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "branchcode", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { is_deferrable => 1, 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:9Qc6VbOUqX83upThUC//oA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-02-07 23:10:36 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ew9HTbXixBeTRsJe4b4l/g # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 3ab89d77b6..a676695b0f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -20297,6 +20297,39 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 24338 - Add 'CASH' to default 'PAYMENT_TYPE')\n"; } +$DBversion = '19.11.02.003'; +if( CheckVersion( $DBversion ) ) { + if( !foreign_key_exists( 'repeatable_holidays', 'repeatable_holidays_ibfk_1' ) ) { + $dbh->do(q| + DELETE h + FROM repeatable_holidays h + LEFT JOIN branches b ON h.branchcode=b.branchcode + WHERE b.branchcode IS NULL; + |); + $dbh->do(q| + ALTER TABLE repeatable_holidays + ADD FOREIGN KEY repeatable_holidays_ibfk_1 (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE + |); + } + + if( !foreign_key_exists( 'special_holidays', 'special_holidays_ibfk_1' ) ) { + $dbh->do(q| + DELETE h + FROM special_holidays h + LEFT JOIN branches b ON h.branchcode=b.branchcode + WHERE b.branchcode IS NULL; + |); + $dbh->do(q| + ALTER TABLE special_holidays + ADD FOREIGN KEY special_holidays_ibfk_1 (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE + |); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24289 - Adding foreign keys on *_holidays.branchcode tables)\n"; +} + + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/'; -- 2.39.5