4 bug_number => "BUG_NUMBER",
5 description => "Some tables for ERM",
8 my ($dbh, $out) = @$args{qw(dbh out)};
11 INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
12 VALUES ('ERMModule', '0', NULL, 'Enable the E-Resource management module', 'YesNo');
16 INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton)
17 VALUES (28, 'erm', 'Manage electronic resources', 0)
20 unless ( TableExists('erm_agreements') ) {
22 CREATE TABLE `erm_agreements` (
23 `agreement_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
24 `vendor_id` INT(11) DEFAULT NULL COMMENT 'foreign key to aqbooksellers',
25 `name` VARCHAR(255) NOT NULL COMMENT 'name of the agreement',
26 `description` LONGTEXT DEFAULT NULL COMMENT 'description of the agreement',
27 `status` VARCHAR(80) NOT NULL COMMENT 'current status of the agreement',
28 `closure_reason` VARCHAR(80) DEFAULT NULL COMMENT 'reason of the closure',
29 `is_perpetual` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'is the agreement perpetual',
30 `renewal_priority` VARCHAR(80) DEFAULT NULL COMMENT 'priority of the renewal',
31 `license_info` VARCHAR(80) DEFAULT NULL COMMENT 'info about the license',
32 CONSTRAINT `erm_agreements_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
33 PRIMARY KEY(`agreement_id`)
34 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
39 INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
41 ('ERM_AGREEMENT_STATUS', 1),
42 ('ERM_AGREEMENT_CLOSURE_REASON', 1),
43 ('ERM_AGREEMENT_RENEWAL_PRIORITY', 1)
46 INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
48 ('ERM_AGREEMENT_STATUS', 'active', 'Active'),
49 ('ERM_AGREEMENT_STATUS', 'in_negotiation', 'In negotiation'),
50 ('ERM_AGREEMENT_STATUS', 'closed', 'Closed'),
51 ('ERM_AGREEMENT_CLOSURE_REASON', 'expired', 'Expired'),
52 ('ERM_AGREEMENT_CLOSURE_REASON', 'cancelled', 'Cancelled'),
53 ('ERM_AGREEMENT_RENEWAL_PRIORITY', 'for_review', 'For review'),
54 ('ERM_AGREEMENT_RENEWAL_PRIORITY', 'renew', 'Renew'),
55 ('ERM_AGREEMENT_RENEWAL_PRIORITY', 'cancel', 'Cancel')
58 unless ( TableExists('erm_agreement_periods') ) {
60 CREATE TABLE `erm_agreement_periods` (
61 `agreement_period_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
62 `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement',
63 `started_on` DATE NOT NULL COMMENT 'start of the agreement period',
64 `ended_on` DATE COMMENT 'end of the agreement period',
65 `cancellation_deadline` DATE DEFAULT NULL COMMENT 'Deadline for the cancellation',
66 `notes` mediumtext DEFAULT NULL COMMENT 'notes about this period',
67 CONSTRAINT `erm_agreement_periods_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
68 PRIMARY KEY(`agreement_period_id`)
69 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
73 unless ( TableExists('erm_agreement_user_roles') ) {
75 CREATE TABLE `erm_agreement_user_roles` (
76 `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement',
77 `user_id` INT(11) NOT NULL COMMENT 'link to the user',
78 `role` VARCHAR(80) NOT NULL COMMENT 'role of the user',
79 CONSTRAINT `erm_agreement_users_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
80 CONSTRAINT `erm_agreement_users_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
81 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
85 INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
87 ('ERM_AGREEMENT_USER_ROLES', 1)
90 INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
92 ('ERM_AGREEMENT_USER_ROLES', 'librarian', 'ERM librarian'),
93 ('ERM_AGREEMENT_USER_ROLES', 'subject_specialist', 'Subject specialist')
96 unless ( TableExists('erm_licenses') ) {
98 CREATE TABLE `erm_licenses` (
99 `license_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
100 `name` VARCHAR(255) NOT NULL COMMENT 'name of the license',
101 `description` LONGTEXT DEFAULT NULL COMMENT 'description of the license',
102 `type` VARCHAR(80) NOT NULL COMMENT 'type of the license',
103 `status` VARCHAR(80) NOT NULL COMMENT 'current status of the license',
104 `started_on` DATE COMMENT 'start of the license',
105 `ended_on` DATE COMMENT 'end of the license',
106 PRIMARY KEY(`license_id`)
107 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
110 unless ( TableExists('erm_agreement_licenses') ) {
112 CREATE TABLE `erm_agreement_licenses` (
113 `agreement_license_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
114 `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement',
115 `license_id` INT(11) NOT NULL COMMENT 'link to the license',
116 `status` VARCHAR(80) NOT NULL COMMENT 'current status of the license',
117 `physical_location` VARCHAR(80) DEFAULT NULL COMMENT 'physical location of the license',
118 `notes` mediumtext DEFAULT NULL COMMENT 'notes about this license',
119 `uri` varchar(255) DEFAULT NULL COMMENT 'URI of the license',
120 CONSTRAINT `erm_licenses_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
121 CONSTRAINT `erm_licenses_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE,
122 PRIMARY KEY(`agreement_license_id`),
123 UNIQUE KEY `erm_agreement_licenses_uniq` (`agreement_id`, `license_id`)
124 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
128 INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
130 ('ERM_LICENSE_TYPE', 1),
131 ('ERM_LICENSE_STATUS', 1),
132 ('ERM_AGREEMENT_LICENSE_STATUS', 1),
133 ('ERM_AGREEMENT_LICENSE_LOCATION', 1);
137 INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
139 ('ERM_LICENSE_TYPE', 'local', 'Local'),
140 ('ERM_LICENSE_TYPE', 'consortial', 'Consortial'),
141 ('ERM_LICENSE_TYPE', 'national', 'National'),
142 ('ERM_LICENSE_TYPE', 'alliance', 'Alliance'),
143 ('ERM_LICENSE_STATUS', 'in_negotiation', 'In negotiation'),
144 ('ERM_LICENSE_STATUS', 'not_yet_active', 'Not yet active'),
145 ('ERM_LICENSE_STATUS', 'active', 'Active'),
146 ('ERM_LICENSE_STATUS', 'rejected', 'Rejected'),
147 ('ERM_LICENSE_STATUS', 'expired', 'Expired'),
148 ('ERM_AGREEMENT_LICENSE_STATUS', 'controlling', 'Controlling'),
149 ('ERM_AGREEMENT_LICENSE_STATUS', 'future', 'Future'),
150 ('ERM_AGREEMENT_LICENSE_STATUS', 'history', 'Historic'),
151 ('ERM_AGREEMENT_LICENSE_LOCATION', 'filing_cabinet', 'Filing cabinet'),
152 ('ERM_AGREEMENT_LICENSE_LOCATION', 'cupboard', 'Cupboard');
155 unless ( TableExists('erm_agreement_relationships') ) {
157 CREATE TABLE `erm_agreement_relationships` (
158 `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement',
159 `related_agreement_id` INT(11) NOT NULL COMMENT 'link to the related agreement',
160 `relationship` ENUM('supersedes', 'is-superseded-by', 'provides_post-cancellation_access_for', 'has-post-cancellation-access-in', 'tracks_demand-driven_acquisitions_for', 'has-demand-driven-acquisitions-in', 'has_backfile_in', 'has_frontfile_in', 'related_to') NOT NULL COMMENT 'relationship between the two agreements',
161 `notes` mediumtext DEFAULT NULL COMMENT 'notes about this relationship',
162 CONSTRAINT `erm_agreement_relationships_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
163 CONSTRAINT `erm_agreement_relationships_ibfk_2` FOREIGN KEY (`related_agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
164 PRIMARY KEY(`agreement_id`, `related_agreement_id`)
165 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
169 unless ( TableExists('erm_agreement_documents') ) {
171 CREATE TABLE `erm_agreement_documents` (
172 `document_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
173 `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement',
174 `file_name` varchar(255) DEFAULT NULL COMMENT 'name of the file',
175 `file_type` varchar(255) DEFAULT NULL COMMENT 'type of the file',
176 `file_description` varchar(255) DEFAULT NULL COMMENT 'description of the file',
177 `file_content` longblob DEFAULT NULL COMMENT 'the content of the file',
178 `uploaded_on` datetime DEFAULT NULL COMMENT 'datetime when the file as attached',
179 `physical_location` VARCHAR(255) DEFAULT NULL COMMENT 'physical location of the document',
180 `uri` varchar(255) DEFAULT NULL COMMENT 'URI of the document',
181 `notes` mediumtext DEFAULT NULL COMMENT 'notes about this relationship',
182 CONSTRAINT `erm_agreement_documents_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE,
183 PRIMARY KEY(`document_id`)
184 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
188 unless ( TableExists('erm_eholdings_packages') ) {
190 CREATE TABLE `erm_eholdings_packages` (
191 `package_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
192 `vendor_id` INT(11) DEFAULT NULL COMMENT 'foreign key to aqbooksellers',
193 `name` VARCHAR(255) NOT NULL COMMENT 'name of the package',
194 `external_id` VARCHAR(255) DEFAULT NULL COMMENT 'External key',
195 `provider` ENUM('ebsco') DEFAULT NULL COMMENT 'External provider',
196 `package_type` VARCHAR(80) DEFAULT NULL COMMENT 'type of the package',
197 `content_type` VARCHAR(80) DEFAULT NULL COMMENT 'type of the package',
198 `created_on` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date of creation of the package',
199 CONSTRAINT `erm_packages_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
200 PRIMARY KEY(`package_id`)
201 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
205 unless ( TableExists('erm_eholdings_packages_agreements') ) {
207 CREATE TABLE `erm_eholdings_packages_agreements` (
208 `package_id` INT(11) NOT NULL COMMENT 'link to the package',
209 `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement',
210 UNIQUE KEY `erm_eholdings_packages_agreements_uniq` (`package_id`, `agreement_id`),
211 CONSTRAINT `erm_eholdings_packages_agreements_ibfk_1` FOREIGN KEY (`package_id`) REFERENCES `erm_eholdings_packages` (`package_id`) ON DELETE CASCADE ON UPDATE CASCADE,
212 CONSTRAINT `erm_eholdings_packages_agreements_ibfk_2` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE
213 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
217 unless ( TableExists('erm_eholdings_titles') ) {
219 CREATE TABLE `erm_eholdings_titles` (
220 `title_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
221 `biblio_id` INT(11) DEFAULT NULL,
222 `publication_title` VARCHAR(255) DEFAULT NULL,
223 `external_id` VARCHAR(255) DEFAULT NULL,
224 `print_identifier` VARCHAR(255) DEFAULT NULL,
225 `online_identifier` VARCHAR(255) DEFAULT NULL,
226 `date_first_issue_online` VARCHAR(255) DEFAULT NULL,
227 `num_first_vol_online` VARCHAR(255) DEFAULT NULL,
228 `num_first_issue_online` VARCHAR(255) DEFAULT NULL,
229 `date_last_issue_online` VARCHAR(255) DEFAULT NULL,
230 `num_last_vol_online` VARCHAR(255) DEFAULT NULL,
231 `num_last_issue_online` VARCHAR(255) DEFAULT NULL,
232 `title_url` VARCHAR(255) DEFAULT NULL,
233 `first_author` VARCHAR(255) DEFAULT NULL,
234 `embargo_info` VARCHAR(255) DEFAULT NULL,
235 `coverage_depth` VARCHAR(255) DEFAULT NULL,
236 `notes` VARCHAR(255) DEFAULT NULL,
237 `publisher_name` VARCHAR(255) DEFAULT NULL,
238 `publication_type` VARCHAR(80) DEFAULT NULL,
239 `date_monograph_published_print` VARCHAR(255) DEFAULT NULL,
240 `date_monograph_published_online` VARCHAR(255) DEFAULT NULL,
241 `monograph_volume` VARCHAR(255) DEFAULT NULL,
242 `monograph_edition` VARCHAR(255) DEFAULT NULL,
243 `first_editor` VARCHAR(255) DEFAULT NULL,
244 `parent_publication_title_id` VARCHAR(255) DEFAULT NULL,
245 `preceeding_publication_title_id` VARCHAR(255) DEFAULT NULL,
246 `access_type` VARCHAR(255) DEFAULT NULL,
247 CONSTRAINT `erm_eholdings_titles_ibfk_2` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
248 PRIMARY KEY(`title_id`)
249 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
252 unless ( TableExists('erm_eholdings_resources') ) {
254 CREATE TABLE `erm_eholdings_resources` (
255 `resource_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
256 `title_id` INT(11) NOT NULL,
257 `package_id` INT(11) NOT NULL,
258 `vendor_id` INT(11) DEFAULT NULL,
261 `proxy` VARCHAR(80) DEFAULT NULL,
262 UNIQUE KEY `erm_eholdings_resources_uniq` (`title_id`, `package_id`),
263 CONSTRAINT `erm_eholdings_resources_ibfk_1` FOREIGN KEY (`title_id`) REFERENCES `erm_eholdings_titles` (`title_id`) ON DELETE CASCADE ON UPDATE CASCADE,
264 CONSTRAINT `erm_eholdings_resources_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `erm_eholdings_packages` (`package_id`) ON DELETE CASCADE ON UPDATE CASCADE,
265 CONSTRAINT `erm_eholdings_resources_ibfk_3` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
266 PRIMARY KEY(`resource_id`)
267 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
271 unless ( column_exists('aqbooksellers', 'external_id') ) {
273 ALTER TABLE `aqbooksellers`
274 ADD COLUMN `external_id` VARCHAR(255) DEFAULT NULL
280 INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
282 ('ERM_PACKAGE_TYPE', 1),
283 ('ERM_PACKAGE_CONTENT_TYPE', 1),
284 ('ERM_TITLE_PUBLICATION_TYPE', 1)
288 INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
290 ('ERM_PACKAGE_TYPE', 'local', 'Local'),
291 ('ERM_PACKAGE_TYPE', 'complete', 'Complete'),
292 ('ERM_PACKAGE_CONTENT_TYPE', 'AggregatedFullText', 'Aggregated full'),
293 ('ERM_PACKAGE_CONTENT_TYPE', 'AbstractAndIndex', 'Abstract and index'),
294 ('ERM_PACKAGE_CONTENT_TYPE', 'EBook', 'E-book'),
295 ('ERM_PACKAGE_CONTENT_TYPE', 'MixedContent', 'Mixed content'),
296 ('ERM_PACKAGE_CONTENT_TYPE', 'EJournal', 'E-journal'),
297 ('ERM_PACKAGE_CONTENT_TYPE', 'OnlineReference', 'Online reference'),
298 ('ERM_PACKAGE_CONTENT_TYPE', 'Print', 'Print'),
299 ('ERM_PACKAGE_CONTENT_TYPE', 'StreamingMedia', 'Streaming media'),
300 ('ERM_PACKAGE_CONTENT_TYPE', 'Unknown', 'Unknown'),
301 ('ERM_TITLE_PUBLICATION_TYPE', 'journal', 'Journal'),
302 ('ERM_TITLE_PUBLICATION_TYPE', 'newsletter', 'Newsletter'),
303 ('ERM_TITLE_PUBLICATION_TYPE', 'report', 'Report'),
304 ('ERM_TITLE_PUBLICATION_TYPE', 'proceedings', 'Proceedings'),
305 ('ERM_TITLE_PUBLICATION_TYPE', 'website', 'Website'),
306 ('ERM_TITLE_PUBLICATION_TYPE', 'newspaper', 'Newspaper'),
307 ('ERM_TITLE_PUBLICATION_TYPE', 'unspecified', 'Unspecified'),
308 ('ERM_TITLE_PUBLICATION_TYPE', 'book', 'Book'),
309 ('ERM_TITLE_PUBLICATION_TYPE', 'ebook', 'E-book'),
310 ('ERM_TITLE_PUBLICATION_TYPE', 'bookseries', 'Bookseries'),
311 ('ERM_TITLE_PUBLICATION_TYPE', 'database', 'Database'),
312 ('ERM_TITLE_PUBLICATION_TYPE', 'thesisdissertation', 'Thesis/Dissertation'),
313 ('ERM_TITLE_PUBLICATION_TYPE', 'streamingaudio', 'Streaming audio'),
314 ('ERM_TITLE_PUBLICATION_TYPE', 'streamingvideo', 'Streaming video'),
315 ('ERM_TITLE_PUBLICATION_TYPE', 'audiobook', 'AudioBook');
319 INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
320 VALUES ('ERMProviders', 'local', 'local|ebsco', 'Set the providers for the ERM module', 'multiple');
323 INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
325 ('ERMProviderEbscoCustomerID', '', '', 'Customer ID for EBSCO', 'free'),
326 ('ERMProviderEbscoApiKey', '', '', 'API key for EBSCO', 'free');