Bug 24289: DBRev 19.12.00.011

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2020-01-20 13:56:04 +00:00
parent 2dbce72a07
commit 0d103621ad
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
5 changed files with 75 additions and 40 deletions

View file

@ -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;

View file

@ -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
# 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
=head2 branchcode
Type: belongs_to
Related object: L<Koha::Schema::Result::Branch>
=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.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

View file

@ -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
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9Qc6VbOUqX83upThUC//oA
=head2 branchcode
Type: belongs_to
Related object: L<Koha::Schema::Result::Branch>
=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.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

View file

@ -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";
}

View file

@ -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/';