From ab7d511822ed25c196ee96fd70829ff1a7f0a21a Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Tue, 27 Aug 2024 13:11:19 +0200 Subject: [PATCH] Bug 37592: (follow-up) Change created_at, updated_at to created_on, updated_on As per a discussion in the community chat, this change is more in line with the existing schema. Signed-off-by: LEBSimonsen Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- ...2-add_created_at_updated_at_to_bookings.pl | 36 +++++++++---------- installer/data/mysql/kohastructure.sql | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) 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 index 66a6c7421e..2177a85ee8 100755 --- 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 @@ -3,7 +3,7 @@ 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', + description => 'Add created_on, updated_on fields to bookings table', up => sub { my ($args) = @_; my ( $dbh, $out ) = @{$args}{qw(dbh out)}; @@ -12,50 +12,50 @@ return { SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'bookings' - AND column_name IN ('created_at', 'updated_at') + AND column_name IN ('created_on', 'updated_on') 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...} ); + say_info( $out, q{Columns 'created_on' and 'updated_on' 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' + my $created_on_statement = <<~'SQL'; + ALTER TABLE bookings ADD COLUMN created_on 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' + my $updated_on_statement = <<~'SQL'; + 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' SQL if ( @{$existing_columns} == 0 ) { - if ( $dbh->do("$created_at_statement AFTER `end_date`") ) { - say_success( $out, q{Added column 'bookings.created_at'} ); + if ( $dbh->do("$created_on_statement AFTER `end_date`") ) { + say_success( $out, q{Added column 'bookings.created_on'} ); } else { - say_failure( $out, q{Failed to add column 'bookings.created_at': } . $dbh->errstr ); + say_failure( $out, q{Failed to add column 'bookings.created_on': } . $dbh->errstr ); } - if ( $dbh->do("$updated_at_statement AFTER `created_at`") ) { - say_success( $out, q{Added column 'bookings.updated_at'} ); + if ( $dbh->do("$updated_on_statement AFTER `created_on`") ) { + say_success( $out, q{Added column 'bookings.updated_on'} ); } else { - say_failure( $out, q{Failed to add column 'bookings.updated_at': } . $dbh->errstr ); + say_failure( $out, q{Failed to add column 'bookings.updated_on': } . $dbh->errstr ); } return; } if ( @{$existing_columns} == 1 ) { - foreach my $column ( 'created_at', 'updated_at' ) { + foreach my $column ( 'created_on', 'updated_on' ) { if ( column_exists( 'bookings', $column ) ) { next; } my $statement; - if ( $column eq 'created_at' ) { - $statement = "$created_at_statement AFTER `end_date`"; + if ( $column eq 'created_on' ) { + $statement = "$created_on_statement AFTER `end_date`"; } - if ( $column eq 'updated_at' ) { - $statement = "$updated_at_statement AFTER `created_at`"; + if ( $column eq 'updated_on' ) { + $statement = "$updated_on_statement AFTER `created_on`"; } if ( $dbh->do($statement) ) { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e829cacc62..cf1798e23c 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1217,8 +1217,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', + `created_on` timestamp DEFAULT current_timestamp() COMMENT 'the timestamp for when a booking was created', + `updated_on` 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.5