Browse Source

Bug 18050: DBRev 20.06.00.055

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Jonathan Druart 11 months ago
parent
commit
7b8bcd9dc3
  1. 2
      Koha.pm
  2. 38
      installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl
  3. 39
      installer/data/mysql/updatedatabase.pl

2
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 = "20.06.00.054";
$VERSION = "20.06.00.055";
sub version {
return $VERSION;

38
installer/data/mysql/atomicupdate/bug_18050_aqbudget_constraint.perl

@ -1,38 +0,0 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
my $count_missing_budget = $dbh->selectrow_arrayref(q|
SELECT COUNT(*) FROM aqbudgets ab WHERE NOT EXISTS
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id)
AND budget_period_id IS NOT NULL;
|);
my $message = "";
if($count_missing_budget->[0] > 0) {
$dbh->do(q|
CREATE TABLE _bug_18050_aqbudgets AS
SELECT * FROM aqbudgets ab WHERE NOT EXISTS
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id)
|);
$dbh->do(q|
UPDATE aqbudgets ab SET budget_period_id = NULL
WHERE NOT EXISTS
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id)
|);
$message = ". There are $count_missing_budget->[0] funds in your database that are not linked
to a valid budget. Setting invalid budget id (budget_period_id) to null. The table _bug_18050_aqbudgets
was created with original data. Please check that table and place valid ids in aqbudget table as soon as possible."
}
if ( !foreign_key_exists( 'aqbudgets', 'aqbudgetperiods_ibfk_1' ) ) {
$dbh->do(q|
ALTER TABLE aqbudgets ADD CONSTRAINT `aqbudgetperiods_ibfk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON UPDATE CASCADE ON DELETE CASCADE
|);
NewVersion( $DBversion, 18050, "Add FK constraint on aqbudgets.budget_period_id$message");
} else {
NewVersion( $DBversion, 18050, "FK constraint on aqbudgets.budget already exists");
}
}

39
installer/data/mysql/updatedatabase.pl

@ -23107,6 +23107,45 @@ if ( CheckVersion($DBversion) ) {
NewVersion( $DBversion, 25596, "Add OVERPAYMENT credit type" );
}
$DBversion = '20.06.00.055';
if( CheckVersion( $DBversion ) ) {
my $count_missing_budget = $dbh->selectrow_arrayref(q|
SELECT COUNT(*) FROM aqbudgets ab WHERE NOT EXISTS
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id)
AND budget_period_id IS NOT NULL;
|);
my $message = "";
if($count_missing_budget->[0] > 0) {
$dbh->do(q|
CREATE TABLE _bug_18050_aqbudgets AS
SELECT * FROM aqbudgets ab WHERE NOT EXISTS
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id)
|);
$dbh->do(q|
UPDATE aqbudgets ab SET budget_period_id = NULL
WHERE NOT EXISTS
(SELECT * FROM aqbudgetperiods abp WHERE abp.budget_period_id = ab.budget_period_id)
|);
$message = ". There are $count_missing_budget->[0] funds in your database that are not linked
to a valid budget. Setting invalid budget id (budget_period_id) to null. The table _bug_18050_aqbudgets
was created with original data. Please check that table and place valid ids in aqbudget table as soon as possible."
}
if ( !foreign_key_exists( 'aqbudgets', 'aqbudgetperiods_ibfk_1' ) ) {
$dbh->do(q|
ALTER TABLE aqbudgets ADD CONSTRAINT `aqbudgetperiods_ibfk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON UPDATE CASCADE ON DELETE CASCADE
|);
NewVersion( $DBversion, 18050, "Add FK constraint on aqbudgets.budget_period_id$message");
} else {
NewVersion( $DBversion, 18050, "FK constraint on aqbudgets.budget already exists");
}
}
# 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/';

Loading…
Cancel
Save