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

(-)a/installer/data/mysql/atomicupdate/bug_37601-add-status-field-to-bookings-table.pl (+28 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => '37601',
6
    description => 'Add status column to bookings table',
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @{$args}{qw(dbh out)};
10
11
        if ( column_exists( 'bookings', 'status' ) ) {
12
            say_info( $out, q{Column 'status' already exists in 'bookings' table. Skipping...} );
13
14
            return;
15
        }
16
17
        my $after     = 'AFTER' . ( column_exists( 'bookings', 'updated_at' ) ? q{`updated_at`} : q{`end_date`} );
18
        my $statement = <<~"SQL";
19
            ALTER TABLE `bookings`
20
            ADD COLUMN `status` ENUM('created', 'cancelled') NOT NULL DEFAULT 'created' COMMENT 'current status of the booking' $after;
21
        SQL
22
        if ( $dbh->do($statement) ) {
23
            say_success( $out, q{Added column 'bookings.status'} );
24
        } else {
25
            say_failure( $out, q{Failed to add column 'bookings.status'} );
26
        }
27
    },
28
};
(-)a/installer/data/mysql/kohastructure.sql (-2 / +1 lines)
Lines 1219-1225 CREATE TABLE `bookings` ( Link Here
1219
  `end_date` datetime DEFAULT NULL COMMENT 'the end date of the booking',
1219
  `end_date` datetime DEFAULT NULL COMMENT 'the end date of the booking',
1220
  `creation_date` timestamp DEFAULT current_timestamp() COMMENT 'the timestamp for when a booking was created',
1220
  `creation_date` timestamp DEFAULT current_timestamp() COMMENT 'the timestamp for when a booking was created',
1221
  `modification_date` timestamp DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'the timestamp for when a booking has been updated',
1221
  `modification_date` timestamp DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'the timestamp for when a booking has been updated',
1222
  `status` enum('created', 'cancelled') NOT NULL DEFAULT 'created' COMMENT 'current status of the booking',
1222
  `status` enum('new', 'cancelled', 'completed') NOT NULL DEFAULT 'created' COMMENT 'current status of the booking',
1223
  PRIMARY KEY (`booking_id`),
1223
  PRIMARY KEY (`booking_id`),
1224
  KEY `patron_id` (`patron_id`),
1224
  KEY `patron_id` (`patron_id`),
1225
  KEY `biblio_id` (`biblio_id`),
1225
  KEY `biblio_id` (`biblio_id`),
1226
- 

Return to bug 37601