Bugzilla – Attachment 170161 Details for
Bug 37592
Add a record of creation and modification to bookings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37592: Add created_at, updated_at fields to bookings table
Bug-37592-Add-createdat-updatedat-fields-to-bookin.patch (text/plain), 4.50 KB, created by
Owen Leonard
on 2024-08-08 14:19:31 UTC
(
hide
)
Description:
Bug 37592: Add created_at, updated_at fields to bookings table
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2024-08-08 14:19:31 UTC
Size:
4.50 KB
patch
obsolete
>From b5080bcbbd2a91db15ae36191d8231f015028606 Mon Sep 17 00:00:00 2001 >From: Paul Derscheid <paul.derscheid@lmscloud.de> >Date: Wed, 7 Aug 2024 15:25:25 +0000 >Subject: [PATCH] Bug 37592: Add created_at, updated_at fields to bookings > table > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >--- > ...2-add_created_at_updated_at_to_bookings.pl | 69 +++++++++++++++++++ > installer/data/mysql/kohastructure.sql | 2 + > 2 files changed, 71 insertions(+) > create mode 100755 installer/data/mysql/atomicupdate/bug_37592-add_created_at_updated_at_to_bookings.pl > >diff --git a/installer/data/mysql/atomicupdate/bug_37592-add_created_at_updated_at_to_bookings.pl b/installer/data/mysql/atomicupdate/bug_37592-add_created_at_updated_at_to_bookings.pl >new file mode 100755 >index 0000000000..66a6c7421e >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_37592-add_created_at_updated_at_to_bookings.pl >@@ -0,0 +1,69 @@ >+use Modern::Perl; >+use Koha::Installer::Output qw(say_warning say_failure say_success say_info); >+ >+return { >+ bug_number => '37592', >+ description => 'Add created_at, updated_at fields to bookings table', >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @{$args}{qw(dbh out)}; >+ >+ my $columns_exist_query = <<~'SQL'; >+ SELECT column_name >+ FROM information_schema.COLUMNS >+ WHERE table_name = 'bookings' >+ AND column_name IN ('created_at', 'updated_at') >+ SQL >+ my $existing_columns = $dbh->selectcol_arrayref($columns_exist_query); >+ if ( @{$existing_columns} == 2 ) { >+ say_info( $out, q{Columns 'created_at' and 'updated_at' already exist in 'bookings' table. Skipping...} ); >+ >+ return; >+ } >+ >+ my $created_at_statement = <<~'SQL'; >+ ALTER TABLE bookings ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'The timestamp for when a bookings was created' >+ SQL >+ my $updated_at_statement = <<~'SQL'; >+ ALTER TABLE bookings ADD COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'The timestamp for when a booking has been updated' >+ SQL >+ if ( @{$existing_columns} == 0 ) { >+ if ( $dbh->do("$created_at_statement AFTER `end_date`") ) { >+ say_success( $out, q{Added column 'bookings.created_at'} ); >+ } else { >+ say_failure( $out, q{Failed to add column 'bookings.created_at': } . $dbh->errstr ); >+ } >+ >+ if ( $dbh->do("$updated_at_statement AFTER `created_at`") ) { >+ say_success( $out, q{Added column 'bookings.updated_at'} ); >+ } else { >+ say_failure( $out, q{Failed to add column 'bookings.updated_at': } . $dbh->errstr ); >+ } >+ >+ return; >+ } >+ >+ if ( @{$existing_columns} == 1 ) { >+ foreach my $column ( 'created_at', 'updated_at' ) { >+ if ( column_exists( 'bookings', $column ) ) { >+ next; >+ } >+ >+ my $statement; >+ if ( $column eq 'created_at' ) { >+ $statement = "$created_at_statement AFTER `end_date`"; >+ } >+ >+ if ( $column eq 'updated_at' ) { >+ $statement = "$updated_at_statement AFTER `created_at`"; >+ } >+ >+ if ( $dbh->do($statement) ) { >+ say_success( $out, "Added column 'bookings.$column'" ); >+ } else { >+ say_failure( $out, "Failed to add column 'bookings.$column': " . $dbh->errstr ); >+ } >+ } >+ } >+ }, >+}; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 07b1e78e1f..46afe7aeb3 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1216,6 +1216,8 @@ CREATE TABLE `bookings` ( > `pickup_library_id` varchar(10) NOT NULL COMMENT 'Identifier for booking pickup library', > `start_date` datetime DEFAULT NULL COMMENT 'the start date of the booking', > `end_date` datetime DEFAULT NULL COMMENT 'the end date of the booking', >+ `created_at` timestamp DEFAULT current_timestamp() COMMENT 'the timestamp for when a booking was created', >+ `updated_at` timestamp DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'the timestamp for when a booking has been updated', > PRIMARY KEY (`booking_id`), > KEY `patron_id` (`patron_id`), > KEY `biblio_id` (`biblio_id`), >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37592
:
170144
|
170161
|
170763
|
171254
|
171376
|
171377
|
171378
|
171524
|
171645