From f75bd50d282303ca539434fb4f0d2cadae179afa Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 1 Nov 2024 18:11:42 -0300 Subject: [PATCH] Bug 35659: Use TableExists Signed-off-by: Tomas Cohen Arazi --- installer/data/mysql/db_revs/240600047.pl | 98 ++++++++++++----------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/installer/data/mysql/db_revs/240600047.pl b/installer/data/mysql/db_revs/240600047.pl index 44f39ee95b..bf0b989303 100755 --- a/installer/data/mysql/db_revs/240600047.pl +++ b/installer/data/mysql/db_revs/240600047.pl @@ -7,56 +7,64 @@ return { up => sub { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; - $dbh->do( - q{ - CREATE TABLE IF NOT EXISTS `oai_servers` ( - `oai_server_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', - `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)', - `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', - `servername` longtext NOT NULL COMMENT 'name given to the target by the library', - `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format', - `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records', - `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results', - PRIMARY KEY (`oai_server_id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + + if ( !TableExists('oai_servers') ) { + $dbh->do( + q{ + CREATE TABLE IF NOT EXISTS `oai_servers` ( + `oai_server_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', + `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)', + `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', + `servername` longtext NOT NULL COMMENT 'name given to the target by the library', + `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format', + `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records', + `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results', + PRIMARY KEY (`oai_server_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + } + ); + say_success( $out, "Added new table 'oai_servers'" ); } - ); - say_success( $out, "Added new table 'oai_servers'" ); - $dbh->do( - q{ - CREATE TABLE IF NOT EXISTS `import_oai_biblios` ( - `import_oai_biblio_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', - `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record', - `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier', - `repository` varchar(255) NOT NULL COMMENT 'OAI repository', - `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', - `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', - `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`import_oai_biblio_id`), - KEY biblionumber (biblionumber), - CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + if ( !TableExists('import_oai_biblios') ) { + $dbh->do( + q{ + CREATE TABLE `import_oai_biblios` ( + `import_oai_biblio_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', + `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record', + `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier', + `repository` varchar(255) NOT NULL COMMENT 'OAI repository', + `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', + `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', + `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`import_oai_biblio_id`), + KEY biblionumber (biblionumber), + CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + } + ); + say_success( $out, "Added new table 'import_oai_biblios'" ); } - ); - $dbh->do( - q{ - CREATE TABLE IF NOT EXISTS `import_oai_authorities` ( - `import_oai_authority_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', - `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record', - `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier', - `repository` varchar(255) NOT NULL COMMENT 'OAI repository', - `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', - `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', - `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`import_oai_authority_id`), - KEY authid (authid), - CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + if ( !TableExists('import_oai_authorities') ) { + $dbh->do( + q{ + CREATE TABLE `import_oai_authorities` ( + `import_oai_authority_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', + `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record', + `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier', + `repository` varchar(255) NOT NULL COMMENT 'OAI repository', + `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', + `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', + `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`import_oai_authority_id`), + KEY authid (authid), + CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + } + ); + say_success( $out, "Added new table 'import_oai_authorities'" ); } - ); - say_success( $out, "Added new tables 'import_oai_biblios' and import_oai_authorities" ); $dbh->do( q{ -- 2.39.5