From ccaf8853976da8a7d2577f50dc9e4e719e249037 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jul 2020 16:03:39 +0200 Subject: [PATCH] Bug 24151: DBRev 20.06.00.006 Signed-off-by: Jonathan Druart --- Koha.pm | 2 +- .../data/mysql/atomicupdate/bug_24151.perl | 73 ------------------ installer/data/mysql/updatedatabase.pl | 74 ++++++++++++++++++- 3 files changed, 74 insertions(+), 75 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_24151.perl diff --git a/Koha.pm b/Koha.pm index afeffa88b1..59bf9c7115 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "20.06.00.005"; +$VERSION = "20.06.00.006"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_24151.perl b/installer/data/mysql/atomicupdate/bug_24151.perl deleted file mode 100644 index f5a83d2d29..0000000000 --- a/installer/data/mysql/atomicupdate/bug_24151.perl +++ /dev/null @@ -1,73 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - unless( TableExists( 'pseudonymized_transactions' ) ) { - $dbh->do(q| - CREATE TABLE `pseudonymized_transactions` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `hashed_borrowernumber` VARCHAR(60) NOT NULL, - `has_cardnumber` TINYINT(1) NOT NULL DEFAULT 0, - `title` LONGTEXT, - `city` LONGTEXT, - `state` MEDIUMTEXT default NULL, - `zipcode` varchar(25) default NULL, - `country` MEDIUMTEXT, - `branchcode` varchar(10) NOT NULL default '', - `categorycode` varchar(10) NOT NULL default '', - `dateenrolled` date default NULL, - `sex` varchar(1) default NULL, - `sort1` varchar(80) default NULL, - `sort2` varchar(80) default NULL, - `datetime` datetime default NULL, - `transaction_branchcode` varchar(10) default NULL, - `transaction_type` varchar(16) default NULL, - `itemnumber` int(11) default NULL, - `itemtype` varchar(10) default NULL, - `holdingbranch` varchar(10) default null, - `homebranch` varchar(10) default null, - `location` varchar(80) default NULL, - `itemcallnumber` varchar(255) default NULL, - `ccode` varchar(80) default NULL, - PRIMARY KEY (`id`), - CONSTRAINT `pseudonymized_transactions_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`), - CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`), - CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_3` FOREIGN KEY (`transaction_branchcode`) REFERENCES `branches` (`branchcode`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - |); - } - - $dbh->do(q| - INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) - VALUES ('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo') - |); - $dbh->do(q| - INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) - VALUES ('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple') - |); - $dbh->do(q| - INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) - VALUES ('PseudonymizationTransactionFields','','datetime,transaction_branchcode,transaction_type,itemnumber,itemtype,holdingbranch,homebranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple') - |); - - unless( TableExists( 'pseudonymized_borrower_attributes' ) ) { - $dbh->do(q| - CREATE TABLE pseudonymized_borrower_attributes ( - `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, -- Row id field - `transaction_id` int(11) NOT NULL, - `code` varchar(10) NOT NULL, - `attribute` varchar(255) default NULL, - CONSTRAINT `pseudonymized_borrower_attributes_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `pseudonymized_transactions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `anonymized_borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - |); - } - - unless( column_exists('borrower_attribute_types', 'keep_for_pseudonymization') ) { - $dbh->do(q| - ALTER TABLE borrower_attribute_types ADD COLUMN `keep_for_pseudonymization` TINYINT(1) NOT NULL DEFAULT 0 AFTER `class` - |); - } - - # Always end with this (adjust the bug info) - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 24151 - Add pseudonymized_transactions tables and sysprefs for Pseudonymization)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 0ede6094a4..418ec0835a 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -22241,7 +22241,79 @@ if( CheckVersion( $DBversion ) ) { $dbh->do( "ALTER TABLE borrowers MODIFY COLUMN login_attempts int(4) NOT NULL DEFAULT 0" ); $dbh->do( "UPDATE deletedborrowers SET login_attempts=0 WHERE login_attempts IS NULL" ); $dbh->do( "ALTER TABLE deletedborrowers MODIFY COLUMN login_attempts int(4) NOT NULL DEFAULT 0" ); - NewVersion( $DBversion, 24379, "Set login_attempts NOT NULL)"); + NewVersion( $DBversion, 24379, "Set login_attempts NOT NULL" ); +} + +$DBversion = '20.06.00.006'; +if( CheckVersion( $DBversion ) ) { + unless( TableExists( 'pseudonymized_transactions' ) ) { + $dbh->do(q| + CREATE TABLE `pseudonymized_transactions` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `hashed_borrowernumber` VARCHAR(60) NOT NULL, + `has_cardnumber` TINYINT(1) NOT NULL DEFAULT 0, + `title` LONGTEXT, + `city` LONGTEXT, + `state` MEDIUMTEXT default NULL, + `zipcode` varchar(25) default NULL, + `country` MEDIUMTEXT, + `branchcode` varchar(10) NOT NULL default '', + `categorycode` varchar(10) NOT NULL default '', + `dateenrolled` date default NULL, + `sex` varchar(1) default NULL, + `sort1` varchar(80) default NULL, + `sort2` varchar(80) default NULL, + `datetime` datetime default NULL, + `transaction_branchcode` varchar(10) default NULL, + `transaction_type` varchar(16) default NULL, + `itemnumber` int(11) default NULL, + `itemtype` varchar(10) default NULL, + `holdingbranch` varchar(10) default null, + `homebranch` varchar(10) default null, + `location` varchar(80) default NULL, + `itemcallnumber` varchar(255) default NULL, + `ccode` varchar(80) default NULL, + PRIMARY KEY (`id`), + CONSTRAINT `pseudonymized_transactions_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`), + CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`), + CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_3` FOREIGN KEY (`transaction_branchcode`) REFERENCES `branches` (`branchcode`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + |); + } + + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) + VALUES ('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo') + |); + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) + VALUES ('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple') + |); + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) + VALUES ('PseudonymizationTransactionFields','','datetime,transaction_branchcode,transaction_type,itemnumber,itemtype,holdingbranch,homebranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple') + |); + + unless( TableExists( 'pseudonymized_borrower_attributes' ) ) { + $dbh->do(q| + CREATE TABLE pseudonymized_borrower_attributes ( + `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, -- Row id field + `transaction_id` int(11) NOT NULL, + `code` varchar(10) NOT NULL, + `attribute` varchar(255) default NULL, + CONSTRAINT `pseudonymized_borrower_attributes_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `pseudonymized_transactions` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `anonymized_borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + |); + } + + unless( column_exists('borrower_attribute_types', 'keep_for_pseudonymization') ) { + $dbh->do(q| + ALTER TABLE borrower_attribute_types ADD COLUMN `keep_for_pseudonymization` TINYINT(1) NOT NULL DEFAULT 0 AFTER `class` + |); + } + + NewVersion( $DBversion, 24151, "Add pseudonymized_transactions tables and sysprefs for Pseudonymization" ); } # SEE bug 13068 -- 2.39.5