Bug 25040: monkeypatch Schema::Loader for recent MariaDB

Recent versions of MariaDB changed the output of 'DESCRIBE' for
timestamp columns with defaults from `CURRENT_TIMESTAMP` to
`current_timestamp()`.  As such the code inside
DBIx::Class::Schema::Loader which catches such cases and outputs
`\"current_timestamp"` as a sensible cross platform default is missed
and this leads of inconsistent class files and bugs with out default
lookup code in Koha::Objects.

This patch serves as a backport of the code I have submitted upstream
such that out developers can continue to use update_dbix_class_files.pl
to build their schema classes from the database and regardless of their
db server version get a consistently correct output.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2020-04-03 11:16:39 +01:00
parent 9ac2ddda0b
commit 3dd79180f3
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 65 additions and 2 deletions

View File

@ -0,0 +1,59 @@
use utf8;
package Koha::Schema::Loader::mysql;
# Copyright 2020 PTFS Europe
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use base 'DBIx::Class::Schema::Loader::DBI::mysql';
use mro 'c3';
use Scalar::Util 'blessed';
# This is being upstreamed, but for now lets make sure whatever version of DBIx::Class::Schema::Loader you are using,
# we will catch MariaDB current_timestamp() and convert it to \"current_timestamp" correctly.
sub _extra_column_info {
no warnings 'uninitialized';
my ( $self, $table, $col, $info, $dbi_info ) = @_;
my %extra_info;
if ( $dbi_info->{mysql_is_auto_increment} ) {
$extra_info{is_auto_increment} = 1;
}
if ( $dbi_info->{mysql_type_name} =~ /\bunsigned\b/i ) {
$extra_info{extra}{unsigned} = 1;
}
if ( $dbi_info->{mysql_values} ) {
$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->{mysql_type_name} ) eq 'timestamp'
)
{
my $current_timestamp = 'current_timestamp';
$extra_info{default_value} = \$current_timestamp;
}
return \%extra_info;
}
1;

View File

@ -19,7 +19,6 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use DBIx::Class::Schema::Loader qw/ make_schema_at /;
use Getopt::Long;
@ -99,7 +98,12 @@ if (! defined $db_name ) {
make_schema_at(
"Koha::Schema",
{ debug => 1, dump_directory => $path, preserve_case => 1 },
["DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",$db_user, $db_passwd ]
[
"DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",
$db_user,
$db_passwd,
{ loader_class => 'Koha::Schema::Loader::mysql' }
]
);
}