View | Details | Raw Unified | Return to bug 33970
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug_33970.pl (-1 / +48 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "33970",
5
    description => "Add 'backend' column and to composite primary key in illrequestattributes",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        if ( !column_exists( 'illrequestattributes', 'backend' ) ) {
11
12
            say $out "Adding 'backend' column to 'illrequestattributes' table";
13
            $dbh->do(
14
                q{ ALTER TABLE illrequestattributes ADD COLUMN backend varchar(80) NOT NULL COMMENT 'API ILL backend name' AFTER illrequest_id }
15
            );
16
17
            say $out "Dropping illrequestattributes_ifk foreign key in 'illrequestattributes' table ";
18
            $dbh->do(q{ ALTER TABLE illrequestattributes DROP FOREIGN KEY illrequestattributes_ifk });
19
20
            say $out "Dropping primary key in 'illrequestattributes' table ";
21
            $dbh->do(q{ ALTER TABLE illrequestattributes DROP PRIMARY KEY });
22
23
            say $out "Creating new primary key in 'illrequestattributes' table ";
24
            $dbh->do(q{ ALTER TABLE illrequestattributes ADD PRIMARY KEY( illrequest_id, backend, type (191)) });
25
26
            say $out "Creating new foreign key constraint in 'illrequestattributes' table ";
27
            $dbh->do(
28
                q{
29
                    ALTER TABLE illrequestattributes ADD CONSTRAINT illrequestattributes_ifk
30
                    FOREIGN KEY(illrequest_id)
31
                    REFERENCES illrequests(illrequest_id)
32
                    ON DELETE CASCADE ON UPDATE CASCADE;
33
                }
34
            );
35
36
            say $out "Updating backend value for all pre-existing illrequestattributes";
37
            $dbh->do(
38
                q{
39
                    UPDATE
40
                    illrequestattributes ira,
41
                    illrequests ir
42
                    SET ira.backend = ir.backend
43
                    WHERE ira . illrequest_id = ir.illrequest_id;
44
                }
45
            );
46
        }
47
    },
48
};

Return to bug 33970