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

(-)a/installer/data/mysql/atomicupdate/bug_40665-add_booking_id_issues_old_issues.pl (-1 / +55 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "CHANGEME",
6
    description => "Add booking_id to issues and old_issues tables to link checkouts to bookings",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        if ( !column_exists( 'issues', 'booking_id' ) ) {
12
            $dbh->do(
13
                q{
14
                ALTER TABLE issues
15
                ADD COLUMN booking_id int(11) DEFAULT NULL
16
                COMMENT 'foreign key linking this checkout to the booking it fulfills'
17
                AFTER itemnumber
18
            }
19
            );
20
21
            $dbh->do(
22
                q{
23
                ALTER TABLE issues
24
                ADD CONSTRAINT issues_booking_id_fk
25
                FOREIGN KEY (booking_id) REFERENCES bookings(booking_id)
26
                ON DELETE SET NULL ON UPDATE CASCADE
27
            }
28
            );
29
30
            say_success( $out, "Added column 'issues.booking_id'" );
31
        }
32
33
        if ( !column_exists( 'old_issues', 'booking_id' ) ) {
34
            $dbh->do(
35
                q{
36
                ALTER TABLE old_issues
37
                ADD COLUMN booking_id int(11) DEFAULT NULL
38
                COMMENT 'foreign key linking this checkout to the booking it fulfilled'
39
                AFTER itemnumber
40
            }
41
            );
42
43
            $dbh->do(
44
                q{
45
                ALTER TABLE old_issues
46
                ADD CONSTRAINT old_issues_booking_id_fk
47
                FOREIGN KEY (booking_id) REFERENCES bookings(booking_id)
48
                ON DELETE SET NULL ON UPDATE CASCADE
49
            }
50
            );
51
52
            say_success( $out, "Added column 'old_issues.booking_id'" );
53
        }
54
    },
55
};

Return to bug 40665