Bug 32030: ERM - Periods - DB table erm_agreement_periods
[koha.git] / installer / data / mysql / atomicupdate / erm.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "BUG_NUMBER",
5     description => "Some tables for ERM",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh, $out) = @$args{qw(dbh out)};
9
10         $dbh->do(q{
11             INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
12             VALUES ('ERMModule', '0', NULL, 'Enable the E-Resource management module', 'YesNo');
13         });
14
15         $dbh->do(q{
16             INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton)
17             VALUES (28, 'erm', 'Manage electronic resources', 0)
18         });
19
20         unless ( TableExists('erm_agreements') ) {
21             $dbh->do(q{
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;
35             });
36         }
37
38         $dbh->do(q{
39             INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
40             VALUES
41                 ('ERM_AGREEMENT_STATUS', 1),
42                 ('ERM_AGREEMENT_CLOSURE_REASON', 1),
43                 ('ERM_AGREEMENT_RENEWAL_PRIORITY', 1)
44             });
45         $dbh->do(q{
46             INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
47             VALUES
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')
56         });
57
58         unless ( TableExists('erm_agreement_periods') ) {
59             $dbh->do(q{
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;
70             });
71         }
72     },
73 };