From 0d103621ada02496c1aa2ee4e6300b683b5a105f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 20 Jan 2020 13:56:04 +0000 Subject: [PATCH] Bug 24289: DBRev 19.12.00.011 Signed-off-by: Martin Renvoize --- Koha.pm | 2 +- Koha/Schema/Result/RepeatableHoliday.pm | 25 ++++++++++++--- Koha/Schema/Result/SpecialHoliday.pm | 25 ++++++++++++--- .../data/mysql/atomicupdate/bug_24289.perl | 31 ------------------ installer/data/mysql/updatedatabase.pl | 32 +++++++++++++++++++ 5 files changed, 75 insertions(+), 40 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_24289.perl diff --git a/Koha.pm b/Koha.pm index 23cb34ae81..43f20e9722 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.12.00.010"; +$VERSION = "19.12.00.011"; sub version { return $VERSION; diff --git a/Koha/Schema/Result/RepeatableHoliday.pm b/Koha/Schema/Result/RepeatableHoliday.pm index d1185c4fe8..f89f10a2f4 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-01-20 13:57:27 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bBw2WEvzF5sX+AOteNsPPQ # 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..f398f209f9 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-01-20 13:57:27 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:cj8Oveni0l6kAR/azmw4SA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/installer/data/mysql/atomicupdate/bug_24289.perl b/installer/data/mysql/atomicupdate/bug_24289.perl deleted file mode 100644 index 231e1ab88b..0000000000 --- a/installer/data/mysql/atomicupdate/bug_24289.perl +++ /dev/null @@ -1,31 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -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"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 61eb449ed8..694ee98fd5 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -20515,6 +20515,38 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 21520 - Add rule_order and rule_operator fields to oai_sets_mappings table)\n"; } +$DBversion = '19.12.00.010'; +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