View | Details | Raw Unified | Return to bug 37901
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug_37901.pl (-1 / +41 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "37901",
6
    description => "Update pseudonymized_borrower_attributes to pseudonymized_metadata_values",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        if ( TableExists('pseudonymized_borrower_attributes') ) {
12
            say_info( $out, "Renaming table 'pseudonymized_borrower_attributes' to 'pseudonymized_metadata_values" );
13
            $dbh->do(
14
                q{ 
15
                    CREATE TABLE `pseudonymized_metadata_values` (
16
                    `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Row id field',
17
                    `transaction_id` int(11) NOT NULL,
18
                    `tablename` varchar(64) NOT NULL COMMENT 'Name of the related table',
19
                    `key` varchar(64) NOT NULL COMMENT 'key for the metadata',
20
                    `value` varchar(255) DEFAULT NULL COMMENT 'value for the metadata',
21
                    PRIMARY KEY (`id`),
22
                    KEY `pseudonymized_metadata_values_ibfk_1` (`transaction_id`),
23
                    CONSTRAINT `pseudonymized_metadata_values_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `pseudonymized_transactions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
24
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
25
                }
26
            );
27
28
            $dbh->do(
29
                q{ 
30
                    INSERT INTO pseudonymized_metadata_values( transaction_id, tablename, `key`, value )
31
                    SELECT transaction_id, 'borrower_attributes', code, attribute
32
                    FROM pseudonymized_borrower_attributes; 
33
                }
34
            );
35
36
            $dbh->do(q{ DROP TABLE pseudonymized_borrower_attributes; });
37
        }
38
39
        say_success( $out, "Finished" );
40
    },
41
};

Return to bug 37901