5 description => "Add ERM Usage Statistics module",
8 my ( $dbh, $out ) = @$args{qw(dbh out)};
10 unless ( TableExists('erm_usage_data_providers') ) {
13 CREATE TABLE `erm_usage_data_providers` (
14 `erm_usage_data_provider_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
15 `name` varchar(80) NOT NULL COMMENT 'name of the data provider',
16 `description` longtext DEFAULT NULL COMMENT 'description of the data provider',
17 `active` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'current status of the harvester - active/inactive',
18 `method` varchar(80) DEFAULT NULL COMMENT 'method of the harvester',
19 `aggregator` varchar(80) DEFAULT NULL COMMENT 'aggregator of the harvester',
20 `service_type` varchar(80) DEFAULT NULL COMMENT 'service_type of the harvester',
21 `service_url` varchar(80) DEFAULT NULL COMMENT 'service_url of the harvester',
22 `report_release` varchar(80) DEFAULT NULL COMMENT 'report_release of the harvester',
23 `customer_id` varchar(50) DEFAULT NULL COMMENT 'sushi customer id',
24 `requestor_id` varchar(50) DEFAULT NULL COMMENT 'sushi requestor id',
25 `api_key` varchar(80) DEFAULT NULL COMMENT 'sushi api key',
26 `requestor_name` varchar(80) DEFAULT NULL COMMENT 'requestor name',
27 `requestor_email` varchar(80) DEFAULT NULL COMMENT 'requestor email',
28 `report_types` varchar(255) DEFAULT NULL COMMENT 'report types provided by the harvester',
29 PRIMARY KEY (`erm_usage_data_provider_id`)
30 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
34 say $out "Added new table 'erm_usage_data_providers'";
37 unless ( TableExists('erm_counter_files') ) {
40 CREATE TABLE `erm_counter_files` (
41 `erm_counter_files_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
42 `usage_data_provider_id` int(11) DEFAULT NULL COMMENT 'foreign key to erm_usage_data_providers',
43 `type` varchar(80) DEFAULT NULL COMMENT 'type of counter file',
44 `filename` varchar(80) DEFAULT NULL COMMENT 'name of the counter file',
45 `file_content` longblob DEFAULT NULL COMMENT 'content of the counter file',
46 `date_uploaded` timestamp DEFAULT NULL DEFAULT current_timestamp() COMMENT 'counter file upload date',
47 PRIMARY KEY (`erm_counter_files_id`),
48 CONSTRAINT `erm_counter_files_ibfk_1` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE
49 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
53 say $out "Added new table 'erm_counter_files'";
56 unless ( TableExists('erm_counter_logs') ) {
59 CREATE TABLE `erm_counter_logs` (
60 `erm_counter_log_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
61 `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key to borrowers',
62 `counter_files_id` int(11) DEFAULT NULL COMMENT 'foreign key to erm_counter_files',
63 `usage_data_provider_id` int(11) DEFAULT NULL COMMENT 'foreign key to erm_usage_data_providers',
64 `importdate` timestamp DEFAULT NULL DEFAULT current_timestamp() COMMENT 'counter file import date',
65 `filename` varchar(80) DEFAULT NULL COMMENT 'name of the counter file',
66 `logdetails` longtext DEFAULT NULL COMMENT 'details from the counter log',
67 PRIMARY KEY (`erm_counter_log_id`),
68 CONSTRAINT `erm_counter_log_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
69 CONSTRAINT `erm_counter_log_ibfk_2` FOREIGN KEY (`counter_files_id`) REFERENCES `erm_counter_files` (`erm_counter_files_id`) ON DELETE CASCADE ON UPDATE CASCADE,
70 CONSTRAINT `erm_counter_log_ibfk_3` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE
71 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
75 say $out "Added new table 'erm_counter_logs'";
78 unless ( TableExists('erm_usage_titles') ) {
81 CREATE TABLE `erm_usage_titles` (
82 `title_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
83 `title` mediumtext DEFAULT NULL COMMENT 'item title',
84 `usage_data_provider_id` int(11) NOT NULL COMMENT 'platform the title is harvested by',
85 `title_doi` varchar(255) DEFAULT NULL COMMENT 'DOI number for the title',
86 `proprietary_id` varchar(255) DEFAULT NULL COMMENT 'Proprietary_ID for the title',
87 `platform` varchar(255) DEFAULT NULL COMMENT 'platform for the title',
88 `print_issn` varchar(255) DEFAULT NULL COMMENT 'Print ISSN number for the title',
89 `online_issn` varchar(255) DEFAULT NULL COMMENT 'Online ISSN number for the title',
90 `title_uri` varchar(255) DEFAULT NULL COMMENT 'URI number for the title',
91 `publisher` varchar(255) DEFAULT NULL COMMENT 'Publisher for the title',
92 `publisher_id` varchar(255) DEFAULT NULL COMMENT 'Publisher ID for the title',
93 `isbn` varchar(255) DEFAULT NULL COMMENT 'ISBN of the title',
94 PRIMARY KEY (`title_id`),
95 CONSTRAINT `erm_usage_titles_ibfk_1` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE
96 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
100 say $out "Added new table 'erm_usage_titles'";
103 unless ( TableExists('erm_usage_platforms') ) {
106 CREATE TABLE `erm_usage_platforms` (
107 `platform_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
108 `platform` varchar(255) DEFAULT NULL COMMENT 'item title',
109 `usage_data_provider_id` int(11) NOT NULL COMMENT 'data provider the platform is harvested by',
110 PRIMARY KEY (`platform_id`),
111 CONSTRAINT `erm_usage_platforms_ibfk_1` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE
112 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
116 say $out "Added new table 'erm_usage_platforms'";
119 unless ( TableExists('erm_usage_databases') ) {
122 CREATE TABLE `erm_usage_databases` (
123 `database_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
124 `database` varchar(255) DEFAULT NULL COMMENT 'item title',
125 `platform` varchar(255) DEFAULT NULL COMMENT 'database platform',
126 `publisher` varchar(255) DEFAULT NULL COMMENT 'Publisher for the database',
127 `publisher_id` varchar(255) DEFAULT NULL COMMENT 'Publisher ID for the database',
128 `usage_data_provider_id` int(11) NOT NULL COMMENT 'data provider the database is harvested by',
129 PRIMARY KEY (`database_id`),
130 CONSTRAINT `erm_usage_databases_ibfk_1` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE
131 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
135 say $out "Added new table 'erm_usage_databases'";
138 unless ( TableExists('erm_usage_items') ) {
141 CREATE TABLE `erm_usage_items` (
142 `item_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
143 `item` varchar(500) DEFAULT NULL COMMENT 'item title',
144 `platform` varchar(255) DEFAULT NULL COMMENT 'item platform',
145 `publisher` varchar(255) DEFAULT NULL COMMENT 'Publisher for the item',
146 `usage_data_provider_id` int(11) NOT NULL COMMENT 'data provider the database is harvested by',
147 PRIMARY KEY (`item_id`),
148 CONSTRAINT `erm_usage_items_ibfk_1` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE
149 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
153 say $out "Added new table 'erm_usage_items'";
156 unless ( TableExists('erm_usage_mus') ) {
159 CREATE TABLE `erm_usage_mus` (
160 `monthly_usage_summary_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
161 `title_id` int(11) DEFAULT NULL COMMENT 'item title id number',
162 `platform_id` int(11) DEFAULT NULL COMMENT 'platform id number',
163 `database_id` int(11) DEFAULT NULL COMMENT 'database id number',
164 `item_id` int(11) DEFAULT NULL COMMENT 'item id number',
165 `usage_data_provider_id` int(11) DEFAULT NULL COMMENT 'item title id number',
166 `year` int(4) DEFAULT NULL COMMENT 'year of usage statistics',
167 `month` int(2) DEFAULT NULL COMMENT 'month of usage statistics',
168 `usage_count` int(11) DEFAULT NULL COMMENT 'usage count for the title',
169 `metric_type` varchar(50) DEFAULT NULL COMMENT 'metric type for the usage statistic',
170 `access_type` varchar(50) DEFAULT NULL COMMENT 'access type for the usage statistic',
171 `yop` varchar(255) DEFAULT NULL COMMENT 'year of publication for the usage statistic',
172 `report_type` varchar(50) DEFAULT NULL COMMENT 'report type for the usage statistic',
173 PRIMARY KEY (`monthly_usage_summary_id`),
174 CONSTRAINT `erm_usage_mus_ibfk_1` FOREIGN KEY (`title_id`) REFERENCES `erm_usage_titles` (`title_id`) ON DELETE CASCADE ON UPDATE CASCADE,
175 CONSTRAINT `erm_usage_mus_ibfk_2` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE,
176 CONSTRAINT `erm_usage_mus_ibfk_3` FOREIGN KEY (`platform_id`) REFERENCES `erm_usage_platforms` (`platform_id`) ON DELETE CASCADE ON UPDATE CASCADE,
177 CONSTRAINT `erm_usage_mus_ibfk_4` FOREIGN KEY (`database_id`) REFERENCES `erm_usage_databases` (`database_id`) ON DELETE CASCADE ON UPDATE CASCADE,
178 CONSTRAINT `erm_usage_mus_ibfk_5` FOREIGN KEY (`item_id`) REFERENCES `erm_usage_items` (`item_id`) ON DELETE CASCADE ON UPDATE CASCADE
179 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
183 say $out "Added new table 'erm_usage_mus'";
186 unless ( TableExists('erm_usage_yus') ) {
189 CREATE TABLE `erm_usage_yus` (
190 `yearly_usage_summary_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
191 `title_id` int(11) DEFAULT NULL COMMENT 'item title id number',
192 `platform_id` int(11) DEFAULT NULL COMMENT 'platform id number',
193 `database_id` int(11) DEFAULT NULL COMMENT 'database id number',
194 `item_id` int(11) DEFAULT NULL COMMENT 'item id number',
195 `usage_data_provider_id` int(11) DEFAULT NULL COMMENT 'item title id number',
196 `year` int(4) DEFAULT NULL COMMENT 'year of usage statistics',
197 `totalcount` int(11) DEFAULT NULL COMMENT 'usage count for the title',
198 `metric_type` varchar(50) DEFAULT NULL COMMENT 'metric type for the usage statistic',
199 `access_type` varchar(50) DEFAULT NULL COMMENT 'access type for the usage statistic',
200 `yop` varchar(255) DEFAULT NULL COMMENT 'year of publication for the usage statistic',
201 `report_type` varchar(50) DEFAULT NULL COMMENT 'report type for the usage statistic',
202 PRIMARY KEY (`yearly_usage_summary_id`),
203 CONSTRAINT `erm_usage_yus_ibfk_1` FOREIGN KEY (`title_id`) REFERENCES `erm_usage_titles` (`title_id`) ON DELETE CASCADE ON UPDATE CASCADE,
204 CONSTRAINT `erm_usage_yus_ibfk_2` FOREIGN KEY (`usage_data_provider_id`) REFERENCES `erm_usage_data_providers` (`erm_usage_data_provider_id`) ON DELETE CASCADE ON UPDATE CASCADE,
205 CONSTRAINT `erm_usage_yus_ibfk_3` FOREIGN KEY (`platform_id`) REFERENCES `erm_usage_platforms` (`platform_id`) ON DELETE CASCADE ON UPDATE CASCADE,
206 CONSTRAINT `erm_usage_yus_ibfk_4` FOREIGN KEY (`database_id`) REFERENCES `erm_usage_databases` (`database_id`) ON DELETE CASCADE ON UPDATE CASCADE,
207 CONSTRAINT `erm_usage_yus_ibfk_5` FOREIGN KEY (`item_id`) REFERENCES `erm_usage_items` (`item_id`) ON DELETE CASCADE ON UPDATE CASCADE
208 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
212 say $out "Added new table 'erm_usage_yus'";
215 unless ( TableExists('erm_default_usage_reports') ) {
218 CREATE TABLE `erm_default_usage_reports` (
219 `erm_default_usage_report_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
220 `report_name` varchar(50) DEFAULT NULL COMMENT 'name of the default report',
221 `report_url_params` longtext DEFAULT NULL COMMENT 'url params for the default report',
222 PRIMARY KEY (`erm_default_usage_report_id`)
223 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
227 say $out "Added new table 'erm_default_usage_reports'";
232 INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
234 ('ERM_REPORT_TYPES', 1),
235 ('ERM_PLATFORM_REPORTS_METRICS', 1),
236 ('ERM_DATABASE_REPORTS_METRICS', 1),
237 ('ERM_TITLE_REPORTS_METRICS', 1),
238 ('ERM_ITEM_REPORTS_METRICS', 1);
243 INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
245 ('ERM_REPORT_TYPES', 'PR', 'PR - Platform master report'),
246 ('ERM_REPORT_TYPES', 'PR_P1', 'PR_P1 - Platform usage'),
247 ('ERM_REPORT_TYPES', 'DR', 'DR - Database master report'),
248 ('ERM_REPORT_TYPES', 'DR_D1', 'DR_D1 - Database search and item usage'),
249 ('ERM_REPORT_TYPES', 'DR_D2', 'DR_D2 - Database access denied'),
250 ('ERM_REPORT_TYPES', 'TR', 'TR - Title master report'),
251 ('ERM_REPORT_TYPES', 'TR_B1', 'TR_B1 - Book requests (excluding OA_Gold)'),
252 ('ERM_REPORT_TYPES', 'TR_B2', 'TR_B2 - Book access denied'),
253 ('ERM_REPORT_TYPES', 'TR_B3', 'TR_B3 - Book usage by access type'),
254 ('ERM_REPORT_TYPES', 'TR_J1', 'TR_J1 - Journal requests (excluding OA_Gold)'),
255 ('ERM_REPORT_TYPES', 'TR_J2', 'TR_J2 - Journal access denied'),
256 ('ERM_REPORT_TYPES', 'TR_J3', 'TR_J3 - Journal usage by access type'),
257 ('ERM_REPORT_TYPES', 'TR_J4', 'TR_J4 - Journal requests by YOP(excluding OA_Gold)'),
258 ('ERM_REPORT_TYPES', 'IR', 'IR - Item master report'),
259 ('ERM_REPORT_TYPES', 'IR_A1', 'IR_A1 - Journal article requests'),
260 ('ERM_REPORT_TYPES', 'IR_M1', 'IR_M1 - Multimedia item requests'),
261 ('ERM_PLATFORM_REPORTS_METRICS', 'Searches_Platform', 'Searches platform'),
262 ('ERM_PLATFORM_REPORTS_METRICS', 'Total_Item_Investigations', 'Total item investigations'),
263 ('ERM_PLATFORM_REPORTS_METRICS', 'Total_Item_Requests', 'Total item requests'),
264 ('ERM_PLATFORM_REPORTS_METRICS', 'Unique_Item_Investigations', 'Unique item investigations'),
265 ('ERM_PLATFORM_REPORTS_METRICS', 'Unique_Item_Requests', 'Unique item requests'),
266 ('ERM_PLATFORM_REPORTS_METRICS', 'Unique_Title_Investigations', 'Unique title investigations'),
267 ('ERM_PLATFORM_REPORTS_METRICS', 'Unique_Title_Requests', 'Unique title requests'),
268 ('ERM_DATABASE_REPORTS_METRICS', 'Searches_Automated', 'Searches automated'),
269 ('ERM_DATABASE_REPORTS_METRICS', 'Searches_Federated', 'Searches federated'),
270 ('ERM_DATABASE_REPORTS_METRICS', 'Searches_Regular', 'Searches regular'),
271 ('ERM_DATABASE_REPORTS_METRICS', 'Total_Item_Investigations', 'Total item investigations'),
272 ('ERM_DATABASE_REPORTS_METRICS', 'Total_Item_Requests', 'Total item requests'),
273 ('ERM_DATABASE_REPORTS_METRICS', 'Unique_Item_Investigations', 'Unique item investigations'),
274 ('ERM_DATABASE_REPORTS_METRICS', 'Unique_Item_Requests', 'Unique item requests'),
275 ('ERM_DATABASE_REPORTS_METRICS', 'Unique_Title_Investigations', 'Unique title investigations'),
276 ('ERM_DATABASE_REPORTS_METRICS', 'Unique_Title_Requests', 'Unique title requests'),
277 ('ERM_DATABASE_REPORTS_METRICS', 'Limit_Exceeded', 'Limit exceeded'),
278 ('ERM_DATABASE_REPORTS_METRICS', 'No_License', 'No license'),
279 ('ERM_TITLE_REPORTS_METRICS', 'Total_Item_Investigations', 'Total item investigations'),
280 ('ERM_TITLE_REPORTS_METRICS', 'Total_Item_Requests', 'Total item requests'),
281 ('ERM_TITLE_REPORTS_METRICS', 'Unique_Item_Investigations', 'Unique item investigations'),
282 ('ERM_TITLE_REPORTS_METRICS', 'Unique_Item_Requests', 'Unique item requests'),
283 ('ERM_TITLE_REPORTS_METRICS', 'Unique_Title_Investigations', 'Unique title investigations'),
284 ('ERM_TITLE_REPORTS_METRICS', 'Unique_Title_Requests', 'Unique title requests'),
285 ('ERM_TITLE_REPORTS_METRICS', 'Limit_Exceeded', 'Limit exceeded'),
286 ('ERM_TITLE_REPORTS_METRICS', 'No_License', 'No license'),
287 ('ERM_ITEM_REPORTS_METRICS', 'Total_Item_Investigations', 'Total item investigations'),
288 ('ERM_ITEM_REPORTS_METRICS', 'Total_Item_Requests', 'Total item requests'),
289 ('ERM_ITEM_REPORTS_METRICS', 'Unique_Item_Investigations', 'Unique item investigations'),
290 ('ERM_ITEM_REPORTS_METRICS', 'Unique_Item_Requests', 'Unique item requests'),
291 ('ERM_ITEM_REPORTS_METRICS', 'Limit_Exceeded', 'Limit exceeded'),
292 ('ERM_ITEM_REPORTS_METRICS', 'No_License', 'No license');