Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / Schema / Loader / mysql.pm
1 use utf8;
2
3 package Koha::Schema::Loader::mysql;
4
5 # Copyright 2020 PTFS Europe
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23
24 use base 'DBIx::Class::Schema::Loader::DBI::mysql';
25 use mro 'c3';
26
27 use Scalar::Util qw( blessed );
28
29 # This is being upstreamed, but for now lets make sure whatever version of DBIx::Class::Schema::Loader you are using,
30 # we will catch MariaDB current_timestamp() and convert it to \"current_timestamp" correctly.
31 sub _extra_column_info {
32     no warnings 'uninitialized';
33     my ( $self, $table, $col, $info, $dbi_info ) = @_;
34     my %extra_info;
35
36     if ( $dbi_info->{mysql_is_auto_increment} ) {
37         $extra_info{is_auto_increment} = 1;
38     }
39     if ( $dbi_info->{mysql_type_name} =~ /\bunsigned\b/i ) {
40         $extra_info{extra}{unsigned} = 1;
41     }
42     if ( $dbi_info->{mysql_values} ) {
43         $extra_info{extra}{list} = $dbi_info->{mysql_values};
44     }
45     if (
46         ( not blessed $dbi_info)    # isa $sth
47         && lc( $dbi_info->{COLUMN_DEF} ) =~ m/^current_timestamp/
48         && lc( $dbi_info->{mysql_type_name} ) eq 'timestamp'
49       )
50     {
51
52         my $current_timestamp = 'current_timestamp';
53         $extra_info{default_value} = \$current_timestamp;
54     }
55
56     return \%extra_info;
57 }
58
59 1;