From 822c4514614d388ab5bf848d3784418de718e0ee Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 3 Apr 2020 08:47:24 +0100 Subject: [PATCH 1/3] Handle current_timestamp() from MariaDB DESCRIBE At some point, MariaDB started outputing 'current_timestamp()' in the default field when DESCRIBE is called on the table. This is a change from 'CURRENT_TIMESTAMP' in mysql and older versions of mariadb. As such, our equality match started to fail and resulting schema dumps produced `current_timestamp()` instead of `\"current_timestamp"` --- lib/DBIx/Class/Schema/Loader/DBI/mysql.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 1b8611906..8225c462e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -302,7 +302,7 @@ sub _extra_column_info { $extra_info{extra}{list} = $dbi_info->{mysql_values}; } if ((not blessed $dbi_info) # isa $sth - && lc($dbi_info->{COLUMN_DEF}) eq 'current_timestamp' + && lc($dbi_info->{COLUMN_DEF}) =~ m/^current_timestamp/ && lc($dbi_info->{mysql_type_name}) eq 'timestamp') { my $current_timestamp = 'current_timestamp'; From b60ce752ac4edea1f660603dd0346ff6c540b061 Mon Sep 17 00:00:00 2001 From: "Dave Lambley (CTRL Break Consulting Ltd.)" Date: Mon, 18 Jan 2021 17:30:47 +0000 Subject: [PATCH 2/3] Be more specific in regex --- lib/DBIx/Class/Schema/Loader/DBI/mysql.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 8225c462e..031f2c4f4 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -302,7 +302,7 @@ sub _extra_column_info { $extra_info{extra}{list} = $dbi_info->{mysql_values}; } if ((not blessed $dbi_info) # isa $sth - && lc($dbi_info->{COLUMN_DEF}) =~ m/^current_timestamp/ + && lc($dbi_info->{COLUMN_DEF}) =~ m/^current_timestamp(?:\(\))?$/ && lc($dbi_info->{mysql_type_name}) eq 'timestamp') { my $current_timestamp = 'current_timestamp'; From 05cd90c8ac901afe57ccd78a4103e00bcf5dea7a Mon Sep 17 00:00:00 2001 From: "Dave Lambley (CTRL Break Consulting Ltd.)" Date: Mon, 18 Jan 2021 18:30:48 +0000 Subject: [PATCH 3/3] Permit DATETIME types to have current_timestamp() --- lib/DBIx/Class/Schema/Loader/DBI/mysql.pm | 7 +++++-- t/10_02mysql_common.t | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 031f2c4f4..d68fc75a8 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -301,9 +301,12 @@ sub _extra_column_info { if ($dbi_info->{mysql_values}) { $extra_info{extra}{list} = $dbi_info->{mysql_values}; } + + # TODO MariaDB docs say that the precision may be specified inside the + # brackets. if ((not blessed $dbi_info) # isa $sth - && lc($dbi_info->{COLUMN_DEF}) =~ m/^current_timestamp(?:\(\))?$/ - && lc($dbi_info->{mysql_type_name}) eq 'timestamp') { + && $dbi_info->{COLUMN_DEF} =~ m/^current_timestamp(?:\(\))?$/i + && $dbi_info->{mysql_type_name} =~ m/^(?:timestamp|datetime)$/i) { my $current_timestamp = 'current_timestamp'; $extra_info{default_value} = \$current_timestamp; diff --git a/t/10_02mysql_common.t b/t/10_02mysql_common.t index 504e60c12..395859fb1 100644 --- a/t/10_02mysql_common.t +++ b/t/10_02mysql_common.t @@ -116,6 +116,10 @@ dbixcsl_common_tests->new( 'datetime' => { data_type => 'datetime', datetime_undef_if_invalid => 1 }, 'timestamp default current_timestamp' => { data_type => 'timestamp', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 }, + 'timestamp not null default current_timestamp()' + => { data_type => 'timestamp', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 }, + 'datetime not null default current_timestamp()' + => { data_type => 'datetime', default_value => \'current_timestamp', datetime_undef_if_invalid => 1 }, 'time' => { data_type => 'time' }, 'year' => { data_type => 'year' }, 'year(4)' => { data_type => 'year' },