From 220b0ea678c704b7b949c2134f470016389fc62f Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 3 Mar 2025 10:10:08 -0100 Subject: [PATCH] Bug 37901: Preparation: atomic update Rename the table pseudonymized_borrower_attributes to pseudonymized_metadata_values This is so that pseudonymizing other 'extended_attributes' type of data, such as illrequestsattributes, becomes possible. --- .../data/mysql/atomicupdate/bug_37901.pl | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_37901.pl diff --git a/installer/data/mysql/atomicupdate/bug_37901.pl b/installer/data/mysql/atomicupdate/bug_37901.pl new file mode 100755 index 00000000000..611b6c2a32b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_37901.pl @@ -0,0 +1,41 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "37901", + description => "Update pseudonymized_borrower_attributes to pseudonymized_metadata_values", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( TableExists('pseudonymized_borrower_attributes') ) { + say_info( $out, "Renaming table 'pseudonymized_borrower_attributes' to 'pseudonymized_metadata_values" ); + $dbh->do( + q{ + CREATE TABLE `pseudonymized_metadata_values` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Row id field', + `transaction_id` int(11) NOT NULL, + `tablename` varchar(64) NOT NULL COMMENT 'Name of the related table', + `key` varchar(64) NOT NULL COMMENT 'key for the metadata', + `value` varchar(255) DEFAULT NULL COMMENT 'value for the metadata', + PRIMARY KEY (`id`), + KEY `pseudonymized_metadata_values_ibfk_1` (`transaction_id`), + CONSTRAINT `pseudonymized_metadata_values_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `pseudonymized_transactions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + } + ); + + $dbh->do( + q{ + INSERT INTO pseudonymized_metadata_values( transaction_id, tablename, `key`, value ) + SELECT transaction_id, 'borrower_attributes', code, attribute + FROM pseudonymized_borrower_attributes; + } + ); + + $dbh->do(q{ DROP TABLE pseudonymized_borrower_attributes; }); + } + + say_success( $out, "Finished" ); + }, +}; -- 2.39.5