From a03415dbc5dad169fe4ed525e297bf0ad7081283 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 15 May 2020 11:09:53 -0300 Subject: [PATCH] Bug 23019: Update database structure and add atomic update --- .../data/mysql/atomicupdate/bug-23019.perl | 40 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 27 ++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug-23019.perl diff --git a/installer/data/mysql/atomicupdate/bug-23019.perl b/installer/data/mysql/atomicupdate/bug-23019.perl new file mode 100644 index 0000000000..48b3fc263e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-23019.perl @@ -0,0 +1,40 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + # you can use $dbh here like: + # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" ); + + # or perform some test and warn + if( !TableExists( 'import_batches_profile' ) ) { + $dbh->do(q{ + CREATE TABLE `import_batches_profile` ( -- profile for batches of marc records to be imported + `id` int(11) NOT NULL auto_increment, -- unique identifier and primary key + `name` varchar(100) NOT NULL, -- name of this profile + `matcher_id` int(11) default NULL, -- the id of the match rule used (matchpoints.matcher_id) + `template_id` int(11) default NULL, -- the id of the marc modification template + `overlay_action` varchar(50) default NULL, -- how to handle duplicate records + `nomatch_action` varchar(50) default NULL, -- how to handle records where no match is found + `item_action` varchar(50) default NULL, -- what to do with item records + `parse_items` tinyint(1) default NULL, -- should items be parsed + `record_type` varchar(50) default NULL, -- type of record in the batch + `encoding` varchar(50) default NULL, -- file encoding + `format` varchar(50) default NULL, -- marc format + `comments` LONGTEXT, -- any comments added when the file was uploaded + PRIMARY KEY (`id`), + UNIQUE KEY `u_import_batches_profile__name` (`name`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + }); + } + + if(!column_exists('import_batches', 'profile_id')) { + $dbh->do(q{ + ALTER TABLE import_batches ADD COLUMN `profile_id` int(11) default NULL AFTER comments + }); + + $dbh->do(q{ + ALTER TABLE import_batches ADD CONSTRAINT `import_batches_ibfk_1` FOREIGN KEY (`profile_id`) REFERENCES `import_batches_profile` (`id`) ON DELETE SET NULL ON UPDATE SET NULL + }); + } + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 23019, "Add import_batches_profile table and profile_id column in import_batches"); +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index c5a3879662..d165bc19cb 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -692,6 +692,28 @@ CREATE TABLE `export_format` ( PRIMARY KEY (`export_format_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Used for CSV export'; +-- +-- Table structure for table `import_batches_profile` +-- + +DROP TABLE IF EXISTS `import_batches_profile`; +CREATE TABLE `import_batches_profile` ( -- profile for batches of marc records to be imported + `id` int(11) NOT NULL auto_increment, -- unique identifier and primary key + `name` varchar(100) NOT NULL, -- name of this profile + `matcher_id` int(11) default NULL, -- the id of the match rule used (matchpoints.matcher_id) + `template_id` int(11) default NULL, -- the id of the marc modification template + `overlay_action` varchar(50) default NULL, -- how to handle duplicate records + `nomatch_action` varchar(50) default NULL, -- how to handle records where no match is found + `item_action` varchar(50) default NULL, -- what to do with item records + `parse_items` tinyint(1) default NULL, -- should items be parsed + `record_type` varchar(50) default NULL, -- type of record in the batch + `encoding` varchar(50) default NULL, -- file encoding + `format` varchar(50) default NULL, -- marc format + `comments` LONGTEXT, -- any comments added when the file was uploaded + PRIMARY KEY (`id`), + UNIQUE KEY `u_import_batches_profile__name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + -- -- Table structure for table `import_batches` -- @@ -713,8 +735,11 @@ CREATE TABLE `import_batches` ( -- information about batches of marc records tha `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch `file_name` varchar(100), -- the name of the file uploaded `comments` LONGTEXT, -- any comments added when the file was uploaded + `profile_id` int(11) default NULL, PRIMARY KEY (`import_batch_id`), - KEY `branchcode` (`branchcode`) + KEY `branchcode` (`branchcode`), + CONSTRAINT `import_batches_ibfk_1` FOREIGN KEY (`profile_id`) + REFERENCES `import_batches_profile` (`id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- 2.25.0