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

(-)a/Koha/Booking.pm (-4 / +1 lines)
Lines 241-250 on the API. Link Here
241
=cut
241
=cut
242
242
243
sub to_api_mapping {
243
sub to_api_mapping {
244
    return {
244
    return {};
245
        created_on => "creation_date",
246
        updated_on => "modification_date"
247
    };
248
}
245
}
249
246
250
=head3 delete
247
=head3 delete
(-)a/installer/data/mysql/atomicupdate/bug_37592-add_created_at_updated_at_to_bookings.pl (-19 / +21 lines)
Lines 3-9 use Koha::Installer::Output qw(say_warning say_failure say_success say_info); Link Here
3
3
4
return {
4
return {
5
    bug_number  => '37592',
5
    bug_number  => '37592',
6
    description => 'Add created_on, updated_on fields to bookings table',
6
    description => 'Add creation_date, modification_date fields to bookings table',
7
    up          => sub {
7
    up          => sub {
8
        my ($args) = @_;
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @{$args}{qw(dbh out)};
9
        my ( $dbh, $out ) = @{$args}{qw(dbh out)};
Lines 12-61 return { Link Here
12
            SELECT column_name
12
            SELECT column_name
13
            FROM information_schema.COLUMNS
13
            FROM information_schema.COLUMNS
14
            WHERE table_name = 'bookings'
14
            WHERE table_name = 'bookings'
15
                AND column_name IN ('created_on', 'updated_on')
15
                AND column_name IN ('creation_date', 'modification_date')
16
        SQL
16
        SQL
17
        my $existing_columns = $dbh->selectcol_arrayref($columns_exist_query);
17
        my $existing_columns = $dbh->selectcol_arrayref($columns_exist_query);
18
        if ( @{$existing_columns} == 2 ) {
18
        if ( @{$existing_columns} == 2 ) {
19
            say_info( $out, q{Columns 'created_on' and 'updated_on' already exist in 'bookings' table. Skipping...} );
19
            say_info(
20
                $out,
21
                q{Columns 'creation_date' and 'modification_date' already exist in 'bookings' table. Skipping...}
22
            );
20
23
21
            return;
24
            return;
22
        }
25
        }
23
26
24
        my $created_on_statement = <<~'SQL';
27
        my $creation_date_statement = <<~'SQL';
25
            ALTER TABLE bookings ADD COLUMN created_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'The timestamp for when a bookings was created'
28
            ALTER TABLE bookings ADD COLUMN creation_date DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'The datetime for when a bookings was created'
26
        SQL
29
        SQL
27
        my $updated_on_statement = <<~'SQL';
30
        my $modification_date_statement = <<~'SQL';
28
            ALTER TABLE bookings ADD COLUMN updated_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'The timestamp for when a booking has been updated'
31
            ALTER TABLE bookings ADD COLUMN modification_date DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'The datetime for when a booking has been updated'
29
        SQL
32
        SQL
30
        if ( @{$existing_columns} == 0 ) {
33
        if ( @{$existing_columns} == 0 ) {
31
            if ( $dbh->do("$created_on_statement AFTER `end_date`") ) {
34
            if ( $dbh->do("$creation_date_statement AFTER `end_date`") ) {
32
                say_success( $out, q{Added column 'bookings.created_on'} );
35
                say_success( $out, q{Added column 'bookings.creation_date'} );
33
            } else {
36
            } else {
34
                say_failure( $out, q{Failed to add column 'bookings.created_on': } . $dbh->errstr );
37
                say_failure( $out, q{Failed to add column 'bookings.creation_date': } . $dbh->errstr );
35
            }
38
            }
36
39
37
            if ( $dbh->do("$updated_on_statement AFTER `created_on`") ) {
40
            if ( $dbh->do("$modification_date_statement AFTER `creation_date`") ) {
38
                say_success( $out, q{Added column 'bookings.updated_on'} );
41
                say_success( $out, q{Added column 'bookings.modification_date'} );
39
            } else {
42
            } else {
40
                say_failure( $out, q{Failed to add column 'bookings.updated_on': } . $dbh->errstr );
43
                say_failure( $out, q{Failed to add column 'bookings.modification_date': } . $dbh->errstr );
41
            }
44
            }
42
45
43
            return;
46
            return;
44
        }
47
        }
45
48
46
        if ( @{$existing_columns} == 1 ) {
49
        if ( @{$existing_columns} == 1 ) {
47
            foreach my $column ( 'created_on', 'updated_on' ) {
50
            foreach my $column ( 'creation_date', 'modification_date' ) {
48
                if ( column_exists( 'bookings', $column ) ) {
51
                if ( column_exists( 'bookings', $column ) ) {
49
                    next;
52
                    next;
50
                }
53
                }
51
54
52
                my $statement;
55
                my $statement;
53
                if ( $column eq 'created_on' ) {
56
                if ( $column eq 'creation_date' ) {
54
                    $statement = "$created_on_statement AFTER `end_date`";
57
                    $statement = "$creation_date_statement AFTER `end_date`";
55
                }
58
                }
56
59
57
                if ( $column eq 'updated_on' ) {
60
                if ( $column eq 'modification_date' ) {
58
                    $statement = "$updated_on_statement AFTER `created_on`";
61
                    $statement = "$modification_date_statement AFTER `creation_date`";
59
                }
62
                }
60
63
61
                if ( $dbh->do($statement) ) {
64
                if ( $dbh->do($statement) ) {
62
- 

Return to bug 37592