Line 0
Link Here
|
|
|
1 |
use Modern::Perl; |
2 |
|
3 |
return { |
4 |
bug_number => "30708", |
5 |
description => "Add a preservation module", |
6 |
up => sub { |
7 |
my ($args) = @_; |
8 |
my ($dbh, $out) = @$args{qw(dbh out)}; |
9 |
$dbh->do(q{ |
10 |
INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type` ) |
11 |
VALUES ('PreservationModule', '0', NULL, 'Enable the preservation module', 'YesNo') |
12 |
}); |
13 |
say $out "Added new system preference 'PreservationModule'"; |
14 |
|
15 |
$dbh->do(q{ |
16 |
INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type` ) |
17 |
VALUES ('PreservationNotForLoanWaitingListIn', '', '', 'Not for loan to apply to items added to the preservation waiting list', 'TextArea') |
18 |
}); |
19 |
say $out "Added new system preference 'PreservationNotForLoanWaitingListIn'"; |
20 |
|
21 |
$dbh->do(q{ |
22 |
INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type` ) |
23 |
VALUES ('PreservationNotForLoanDefaultTrainIn', '', '', 'Not for loan to apply to items removed from the preservation waiting list', 'TextArea') |
24 |
}); |
25 |
say $out "Added new system preference 'PreservationNotForLoanDefaultTrainIn'"; |
26 |
|
27 |
$dbh->do(q{ |
28 |
INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton) |
29 |
VALUES (30, 'preservation', 'Manage preservation module', 0) |
30 |
}); |
31 |
say $out "Added new permission 'preservation'"; |
32 |
|
33 |
unless ( TableExists('preservation_processings') ) { |
34 |
$dbh->do(q{ |
35 |
CREATE TABLE `preservation_processings` ( |
36 |
`processing_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', |
37 |
`name` varchar(80) NOT NULL COMMENT 'name of the processing', |
38 |
PRIMARY KEY (`processing_id`) |
39 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
40 |
}); |
41 |
say $out "Added new table 'preservation_processings'"; |
42 |
} |
43 |
|
44 |
unless ( TableExists('preservation_trains') ) { |
45 |
$dbh->do(q{ |
46 |
CREATE TABLE `preservation_trains` ( |
47 |
`train_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', |
48 |
`name` varchar(80) NOT NULL COMMENT 'name of the train', |
49 |
`description` varchar(255) NULL COMMENT 'description of the train', |
50 |
`default_processing_id` int(11) NULL COMMENT 'default processing, link to preservation_processings.processing_id', |
51 |
`not_for_loan` varchar(80) NOT NULL DEFAULT 0 COMMENT 'NOT_LOAN authorised value to apply toitem added to this train', |
52 |
`created_on` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'creation date', |
53 |
`closed_on` datetime DEFAULT NULL COMMENT 'closing date', |
54 |
`sent_on` datetime DEFAULT NULL COMMENT 'sending date', |
55 |
`received_on` datetime DEFAULT NULL COMMENT 'receiving date', |
56 |
PRIMARY KEY (`train_id`), |
57 |
CONSTRAINT `preservation_trains_ibfk_1` FOREIGN KEY (`default_processing_id`) REFERENCES `preservation_processings` (`processing_id`) ON DELETE SET NULL ON UPDATE CASCADE |
58 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
59 |
}); |
60 |
say $out "Added new table 'preservation_trains'"; |
61 |
} |
62 |
|
63 |
unless ( TableExists('preservation_processing_attributes') ) { |
64 |
$dbh->do(q{ |
65 |
CREATE TABLE `preservation_processing_attributes` ( |
66 |
`processing_attribute_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', |
67 |
`processing_id` int(11) NOT NULL COMMENT 'link to the processing', |
68 |
`name` varchar(80) NOT NULL COMMENT 'name of the processing attribute', |
69 |
`type` enum('authorised_value', 'free_text', 'db_column') NOT NULL COMMENT 'Type of the processing attribute', |
70 |
`option_source` varchar(80) NULL COMMENT 'source of the possible options for this attribute', |
71 |
PRIMARY KEY (`processing_attribute_id`), |
72 |
CONSTRAINT `preservation_processing_attributes_ibfk_1` FOREIGN KEY (`processing_id`) REFERENCES `preservation_processings` (`processing_id`) ON DELETE CASCADE ON UPDATE CASCADE |
73 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
74 |
}); |
75 |
say $out "Added new table 'preservation_processing_attributes'"; |
76 |
} |
77 |
|
78 |
unless ( TableExists('preservation_trains_items') ) { |
79 |
$dbh->do(q{ |
80 |
CREATE TABLE `preservation_trains_items` ( |
81 |
`train_item_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', |
82 |
`train_id` int(11) NOT NULL COMMENT 'link with preservation_train', |
83 |
`item_id` int(11) NOT NULL COMMENT 'link with items', |
84 |
`processing_id` int(11) NULL COMMENT 'specific processing for this item', |
85 |
`user_train_item_id` int(11) NOT NULL COMMENT 'train item id for this train, starts from 1', |
86 |
`added_on` datetime DEFAULT NULL COMMENT 'added date', |
87 |
PRIMARY KEY (`train_item_id`), |
88 |
UNIQUE KEY (`train_id`,`item_id`), |
89 |
CONSTRAINT `preservation_item_ibfk_1` FOREIGN KEY (`train_id`) REFERENCES `preservation_trains` (`train_id`) ON DELETE CASCADE ON UPDATE CASCADE, |
90 |
CONSTRAINT `preservation_item_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, |
91 |
CONSTRAINT `preservation_item_ibfk_3` FOREIGN KEY (`processing_id`) REFERENCES `preservation_processings` (`processing_id`) ON DELETE SET NULL ON UPDATE CASCADE |
92 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
93 |
}); |
94 |
say $out "Added new table 'preservation_trains_items'"; |
95 |
} |
96 |
|
97 |
unless ( TableExists('preservation_processing_attributes_items') ) { |
98 |
$dbh->do(q{ |
99 |
CREATE TABLE `preservation_processing_attributes_items` ( |
100 |
`processing_attribute_id` int(11) NOT NULL COMMENT 'link with preservation_processing_attributes', |
101 |
`train_item_id` int(11) NOT NULL COMMENT 'link with preservation_trains_items', |
102 |
`value` varchar(255) NULL COMMENT 'value for this attribute', |
103 |
PRIMARY KEY (`processing_attribute_id`,`train_item_id`), |
104 |
CONSTRAINT `preservation_processing_attributes_items_ibfk_1` FOREIGN KEY (`processing_attribute_id`) REFERENCES `preservation_processing_attributes` (`processing_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE, |
105 |
CONSTRAINT `preservation_processing_attributes_items_ibfk_2` FOREIGN KEY (`train_item_id`) REFERENCES `preservation_trains_items` (`train_item_id`) ON DELETE CASCADE ON UPDATE CASCADE |
106 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; |
107 |
}); |
108 |
say $out "Added new table 'preservation_processing_attributes_items'"; |
109 |
} |
110 |
|
111 |
}, |
112 |
}; |