From 7aca9e354d24a3a1ad4455e31d9cf2c7cb412ae1 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 24 Oct 2024 13:59:05 +0000 Subject: [PATCH] Bug 38256: Add a column for a vendor (cherry picked from commit 757664a10e2bea8632c9c44bfe3e9d7f589903fc) --- ...ug_38256-link_vendors_to_data_providers.pl | 37 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 5 ++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_38256-link_vendors_to_data_providers.pl diff --git a/installer/data/mysql/atomicupdate/bug_38256-link_vendors_to_data_providers.pl b/installer/data/mysql/atomicupdate/bug_38256-link_vendors_to_data_providers.pl new file mode 100644 index 00000000000..17ab0069920 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_38256-link_vendors_to_data_providers.pl @@ -0,0 +1,37 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_failure say_success say_info); + +return { + bug_number => "38256", + description => "Link vendors to data providers", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + unless ( column_exists( 'erm_usage_data_providers', 'vendor_id' ) ) { + $dbh->do( + q{ + ALTER TABLE erm_usage_data_providers + ADD COLUMN `vendor_id` int(11) DEFAULT NULL + COMMENT 'the vendor linked to this provider' + AFTER service_platform + } + ); + + say $out "Added new column 'erm_usage_data_providers.vendor'"; + } + + unless ( foreign_key_exists( 'erm_usage_data_providers', 'erm_usage_data_providers_ibfk_1' ) ) { + $dbh->do( + q{ + ALTER TABLE erm_usage_data_providers + ADD CONSTRAINT `erm_usage_data_providers_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + } + ) == 1 + && say_success( + $out, + "Added foreign key 'erm_usage_data_providers_ibfk_1' to column 'erm_usage_data_providers.vendor_id'" + ); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index d56d37fd476..311c8f4f03f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3230,7 +3230,10 @@ CREATE TABLE `erm_usage_data_providers` ( `requestor_email` varchar(80) DEFAULT NULL COMMENT 'requestor email', `report_types` varchar(255) DEFAULT NULL COMMENT 'report types provided by the harvester', `service_platform` varchar(80) DEFAULT NULL COMMENT 'platform if provider requires it', - PRIMARY KEY (`erm_usage_data_provider_id`) + `vendor_id` int(11) DEFAULT NULL COMMENT 'foreign key to aqbooksellers', + PRIMARY KEY (`erm_usage_data_provider_id`), + KEY `erm_usage_data_provider_ibfk_1` (`vendor_id`), + CONSTRAINT `erm_usage_data_provider_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- 2.39.3 (Apple Git-146)