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

(-)a/installer/data/mysql/db_revs/240600029.pl (-11 / +3 lines)
Lines 8-21 return { Link Here
8
        my ($args) = @_;
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @{$args}{qw(dbh out)};
9
        my ( $dbh, $out ) = @{$args}{qw(dbh out)};
10
10
11
        my $columns_exist_query = <<~'SQL';
11
        if ( column_exists( 'bookings', 'creation_date' ) && column_exists( 'bookings', 'modification_date' ) ) {
12
            SELECT column_name
13
            FROM information_schema.COLUMNS
14
            WHERE table_name = 'bookings'
15
                AND column_name IN ('creation_date', 'modification_date')
16
        SQL
17
        my $existing_columns = $dbh->selectcol_arrayref($columns_exist_query);
18
        if ( @{$existing_columns} == 2 ) {
19
            say_info(
12
            say_info(
20
                $out,
13
                $out,
21
                q{Columns 'creation_date' and 'modification_date' already exist in 'bookings' table. Skipping...}
14
                q{Columns 'creation_date' and 'modification_date' already exist in 'bookings' table. Skipping...}
Lines 30-36 return { Link Here
30
        my $modification_date_statement = <<~'SQL';
23
        my $modification_date_statement = <<~'SQL';
31
            ALTER TABLE bookings ADD COLUMN modification_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'the timestamp for when a booking has been updated'
24
            ALTER TABLE bookings ADD COLUMN modification_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'the timestamp for when a booking has been updated'
32
        SQL
25
        SQL
33
        if ( @{$existing_columns} == 0 ) {
26
        unless ( column_exists( 'bookings', 'creation_date' ) && column_exists( 'bookings', 'modification_date' )) {
34
            $dbh->do("$creation_date_statement AFTER `end_date`");
27
            $dbh->do("$creation_date_statement AFTER `end_date`");
35
            say_success( $out, q{Added column 'bookings.creation_date'} );
28
            say_success( $out, q{Added column 'bookings.creation_date'} );
36
29
Lines 40-46 return { Link Here
40
            return;
33
            return;
41
        }
34
        }
42
35
43
        if ( @{$existing_columns} == 1 ) {
36
        if ( column_exists( 'bookings', 'creation_date' ) || column_exists( 'bookings', 'modification_date' ) ) {
44
            foreach my $column ( 'creation_date', 'modification_date' ) {
37
            foreach my $column ( 'creation_date', 'modification_date' ) {
45
                if ( column_exists( 'bookings', $column ) ) {
38
                if ( column_exists( 'bookings', $column ) ) {
46
                    next;
39
                    next;
47
- 

Return to bug 38602