From ffd47c373aa84f19c4dcab4d7f249b622e8adcaa Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 2 May 2024 13:19:05 +0000 Subject: [PATCH] Bug 36755: Atomicupdate file Test plan, k-t-d: 1) Apply patches. 2) Run the following SQL and save the output of each: SHOW CREATE TABLE pseudonymized_borrower_attributes; SHOW CREATE TABLE borrower_attribute_types_branches; SHOW CREATE TABLE borrower_attributes; SHOW CREATE TABLE borrower_attribute_types; 3) Run updatedatabase 4) Run the SQL queries again, compare the output of each with the previous output before updatedatabase. 5) Make sure the only diff between the two is VARCHAR(10) -> VARCHAR(64) Signed-off-by: David Nind Signed-off-by: Kyle M Hall Signed-off-by: Pedro Amorim Signed-off-by: Katrin Fischer --- .../data/mysql/atomicupdate/bug_36755.pl | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_36755.pl diff --git a/installer/data/mysql/atomicupdate/bug_36755.pl b/installer/data/mysql/atomicupdate/bug_36755.pl new file mode 100755 index 0000000000..79116c24a6 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_36755.pl @@ -0,0 +1,72 @@ +use Modern::Perl; + +return { + bug_number => "36755", + description => "Increase length of 'code' column in borrower_attribute_types", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Drop related tables constraints + if ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { + $dbh->do( + q{ALTER TABLE pseudonymized_borrower_attributes DROP FOREIGN KEY anonymized_borrower_attributes_ibfk_2} + ); + } + if ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) { + $dbh->do( + q{ALTER TABLE borrower_attribute_types_branches DROP FOREIGN KEY borrower_attribute_types_branches_ibfk_1} + ); + } + if ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { + $dbh->do(q{ALTER TABLE borrower_attributes DROP FOREIGN KEY borrower_attributes_ibfk_2}); + } + + # Update the column we want + unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) + || foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) + || foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) + { + $dbh->do( + q{ALTER TABLE borrower_attribute_types MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'unique key used to identify each custom field'} + ); + } + + # Update the related tables + unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { + $dbh->do( + q{ALTER TABLE pseudonymized_borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} + ); + } + unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) + { + $dbh->do(q{ALTER TABLE borrower_attribute_types_branches MODIFY COLUMN bat_code VARCHAR(64) DEFAULT NULL}); + } + unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { + $dbh->do( + q{ALTER TABLE borrower_attributes MODIFY COLUMN code VARCHAR(64) NOT NULL COMMENT 'foreign key from the borrower_attribute_types table, defines which custom field this value was entered for'} + ); + } + + # Restore related tables constraints + unless ( foreign_key_exists( 'pseudonymized_borrower_attributes', 'anonymized_borrower_attributes_ibfk_2' ) ) { + $dbh->do( + q{ALTER TABLE pseudonymized_borrower_attributes ADD CONSTRAINT anonymized_borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} + ); + } + unless ( foreign_key_exists( 'borrower_attribute_types_branches', 'borrower_attribute_types_branches_ibfk_1' ) ) + { + $dbh->do( + q{ALTER TABLE borrower_attribute_types_branches ADD CONSTRAINT borrower_attribute_types_branches_ibfk_1 FOREIGN KEY (bat_code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE} + ); + } + unless ( foreign_key_exists( 'borrower_attributes', 'borrower_attributes_ibfk_2' ) ) { + $dbh->do( + q{ALTER TABLE borrower_attributes ADD CONSTRAINT borrower_attributes_ibfk_2 FOREIGN KEY (code) REFERENCES borrower_attribute_types(code) ON DELETE CASCADE ON UPDATE CASCADE} + ); + } + + # HTML customizations + say $out "Increased borrower_attribute_types.code column length from 10 to 64"; + }, +}; -- 2.39.5