Bug 23681: DBRev 22.06.00.037
[koha.git] / installer / data / mysql / db_revs / 220600037.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "23681",
5     description => "Add customisable patron restriction types",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh, $out) = @$args{qw(dbh out)};
9
10         unless ( TableExists('restriction_types') ) {
11             $dbh->do(q{
12                 CREATE TABLE `restriction_types` (
13                     `code` varchar(50) NOT NULL,
14                     `display_text` text NOT NULL,
15                     `is_system` tinyint(1) NOT NULL DEFAULT 0,
16                     `is_default` tinyint(1) NOT NULL DEFAULT 0,
17                     PRIMARY KEY (`code`)
18                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
19             });
20
21             say $out "Added restriction_types table";
22         }
23
24         $dbh->do(q{
25             INSERT IGNORE INTO restriction_types (code, display_text, is_system, is_default) VALUES
26             ('MANUAL',     'Manual',     0, 1),
27             ('OVERDUES',   'Overdues',   1, 0),
28             ('SUSPENSION', 'Suspension', 1, 0),
29             ('DISCHARGE',  'Discharge',  1, 0);
30         });
31         say $out "Added system restriction_types";
32
33         unless ( foreign_key_exists('borrower_debarments', 'borrower_debarments_ibfk_2') ) {
34             $dbh->do(q{
35                 ALTER TABLE borrower_debarments
36                 MODIFY COLUMN type varchar(50) NOT NULL
37             });
38             $dbh->do(q{
39                 ALTER TABLE borrower_debarments
40                 ADD CONSTRAINT `borrower_debarments_ibfk_2` FOREIGN KEY (`type`)  REFERENCES `restriction_types` (`code`) ON DELETE NO ACTION ON UPDATE CASCADE;
41             });
42
43             say $out "Added borrower_debarments relation";
44         }
45
46         $dbh->do(q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 3, 'manage_patron_restrictions', 'Manage patron restrictions')});
47         say $out "Added manage_patron_restrictions permission";
48
49         $dbh->do(q{INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('PatronRestrictionTypes', '0', 'If enabled, it is possible to specify the "type" of patron restriction being applied.', '', 'YesNo');});
50         say $out "Added PatronRestrictionTypes preference";
51     },
52 };