Bug 24857: (QA follow-up) Make update idempotent
[koha.git] / installer / data / mysql / atomicupdate / bug_24857_item_groups.pl
1 use Modern::Perl;
2
3 return {
4     bug_number  => "24857",
5     description => "Add ability to group items on a record",
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`, `options`, `explanation`, `type` ) VALUES
12             ('EnableItemGroups','0','','Enable the item groups feature','YesNo');
13         });
14
15         $dbh->do(q{
16             INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
17             ( 9, 'manage_item_groups', 'Create, update and delete item groups, add or remove items from a item groups');
18         });
19
20         unless ( TableExists('item_groups') ) {
21             $dbh->do(q{
22                 CREATE TABLE `item_groups` (
23                     `item_group_id` INT(11) NOT NULL auto_increment COMMENT "id for the items group",
24                     `biblio_id` INT(11) NOT NULL DEFAULT 0 COMMENT "id for the bibliographic record the group belongs to",
25                     `display_order` INT(4) NOT NULL DEFAULT 0 COMMENT "The 'sort order' for item_groups",
26                     `description` MEDIUMTEXT default NULL COMMENT "A group description",
27                     `created_on` TIMESTAMP NULL COMMENT "Time and date the group was created",
28                     `updated_on` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT "Time and date of the latest change on the group",
29                     PRIMARY KEY  (`item_group_id`),
30                     CONSTRAINT `item_groups_ibfk_1` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
31                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
32             });
33         }
34
35         unless ( TableExists('item_group_items') ) {
36             $dbh->do(q{
37                 CREATE TABLE `item_group_items` (
38                     `item_group_items_id` int(11) NOT NULL auto_increment COMMENT "id for the group/item link",
39                     `item_group_id` INT(11) NOT NULL DEFAULT 0 COMMENT "foreign key making this table a 1 to 1 join from items to item groups",
40                     `item_id` INT(11) NOT NULL DEFAULT 0 COMMENT "foreign key linking this table to the items table",
41                     PRIMARY KEY  (`item_group_items_id`),
42                     UNIQUE KEY (`item_id`),
43                     CONSTRAINT `item_group_items_iifk_1` FOREIGN KEY (`item_id`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
44                     CONSTRAINT `item_group_items_gifk_1` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE CASCADE ON UPDATE CASCADE
45                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
46             });
47         }
48     },
49 }