From a50553ff15815f878b148585ebca001e9723db94 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 4 May 2022 10:48:58 +0100 Subject: [PATCH] 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 Signed-off-by: Tomas Cohen Arazi --- .../data/mysql/atomicupdate/bug_23681.pl | 48 +++++++++++++++++++ ...3681_add_PatronRestrictionTypes_syspref.pl | 14 ------ .../bug_23681_add_debarment_types.pl | 37 -------------- ...681_add_manage_patron_restrictions_perm.pl | 14 ------ 4 files changed, 48 insertions(+), 65 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_23681.pl delete mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl delete mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl delete mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl diff --git a/installer/data/mysql/atomicupdate/bug_23681.pl b/installer/data/mysql/atomicupdate/bug_23681.pl new file mode 100644 index 0000000000..375f5a1459 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_23681.pl @@ -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"; + }, +}; diff --git a/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl b/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl deleted file mode 100644 index 51940e5c65..0000000000 --- a/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl +++ /dev/null @@ -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"; - }, -}; \ No newline at end of file diff --git a/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl b/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl deleted file mode 100644 index 4aac79cb8c..0000000000 --- a/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl +++ /dev/null @@ -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"; - }, -}; \ No newline at end of file diff --git a/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl b/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl deleted file mode 100644 index 396ca8f26b..0000000000 --- a/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl +++ /dev/null @@ -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"; - }, -}; \ No newline at end of file -- 2.39.5