Bug 23681: (QA follow-up) Merge update files

This patch merges the three atomic update files into one and also
adds a check for foreing key existance to make the update idempotent.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2022-05-04 10:48:58 +01:00 committed by Tomas Cohen Arazi
parent 6d62f77e95
commit a50553ff15
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 48 additions and 65 deletions

View file

@ -0,0 +1,48 @@
use Modern::Perl;
return {
bug_number => "23681",
description => "Add customisable patron restriction types",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
$dbh->do(q{
CREATE TABLE IF NOT EXISTS debarment_types (
code varchar(50) NOT NULL PRIMARY KEY,
display_text text NOT NULL,
is_system tinyint(1) NOT NULL DEFAULT 0,
default_value tinyint(1) NOT NULL DEFAULT 0,
can_be_added_manually tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
});
say $out "Added debarment_types table";
$dbh->do(q{
INSERT IGNORE INTO debarment_types (code, display_text, is_system, default_value, can_be_added_manually) VALUES
('MANUAL', 'Manual', 1, 1, 0),
('OVERDUES', 'Overdues', 1, 0, 0),
('SUSPENSION', 'Suspension', 1, 0, 0),
('DISCHARGE', 'Discharge', 1, 0, 0);
});
say $out "Added system debarment_types";
unless ( foreign_key_exists('borrower_debarments', 'borrower_debarments_ibfk_2') ) {
$dbh->do(q{
ALTER TABLE borrower_debarments
MODIFY COLUMN type varchar(50) NOT NULL
});
$dbh->do(q{
ALTER TABLE borrower_debarments
ADD CONSTRAINT borrower_debarments_ibfk_2 FOREIGN KEY (type) REFERENCES debarment_types(code) ON DELETE NO ACTION ON UPDATE CASCADE;
});
say $out "Added borrower_debarments relation";
}
$dbh->do(q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 3, 'manage_patron_restrictions', 'Manage patron restrictions')});
say $out "Added manage_patron_restrictions permission";
$dbh->do(q{INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('PatronRestrictionTypes', '0', 'If enabled, it is possible to specify the "type" of patron restriction being applied.', '', 'YesNo');});
say $out "Added PatronRestrictionTypes preference";
},
};

View file

@ -1,14 +0,0 @@
use Modern::Perl;
return {
bug_number => "23681",
description => "Add PatronRestrictionTypes syspref",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
# Do you stuffs here
$dbh->do(q{INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('PatronRestrictionTypes', '0', 'If enabled, it is possible to specify the "type" of patron restriction being applied.', '', 'YesNo');});
# Print useful stuff here
say $out "Update is going well so far";
},
};

View file

@ -1,37 +0,0 @@
use Modern::Perl;
return {
bug_number => "23681",
description => "Add debarment_types",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
# Do you stuffs here
$dbh->do(q{
CREATE TABLE IF NOT EXISTS debarment_types (
code varchar(50) NOT NULL PRIMARY KEY,
display_text text NOT NULL,
is_system tinyint(1) NOT NULL DEFAULT 0,
default_value tinyint(1) NOT NULL DEFAULT 0,
can_be_added_manually tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
});
$dbh->do(q{
INSERT IGNORE INTO debarment_types (code, display_text, is_system, default_value, can_be_added_manually) VALUES
('MANUAL', 'Manual', 1, 1, 0),
('OVERDUES', 'Overdues', 1, 0, 0),
('SUSPENSION', 'Suspension', 1, 0, 0),
('DISCHARGE', 'Discharge', 1, 0, 0);
});
$dbh->do(q{
ALTER TABLE borrower_debarments
MODIFY COLUMN type varchar(50) NOT NULL
});
$dbh->do(q{
ALTER TABLE borrower_debarments
ADD CONSTRAINT borrower_debarments_ibfk_2 FOREIGN KEY (type) REFERENCES debarment_types(code) ON DELETE NO ACTION ON UPDATE CASCADE;
});
# Print useful stuff here
say $out "Update is going well so far";
},
};

View file

@ -1,14 +0,0 @@
use Modern::Perl;
return {
bug_number => "23681",
description => "Add manage_patron_restrictions_permission",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
# Do you stuffs here
$dbh->do(q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 3, 'manage_patron_restrictions', 'Manage patron restrictions')});
# Print useful stuff here
say $out "Update is going well so far";
},
};