From: Rafael Kitover Date: Sun, 17 Jan 2010 14:19:21 +0000 (+0000) Subject: check for "CURRENT_TIMESTAMP" only for "TIMESTAMP" columns in MySQL X-Git-Tag: 0.05000~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3facc532d150dae0a20e8875922533d97e843850;p=dbsrgits%2FDBIx-Class-Schema-Loader.git check for "CURRENT_TIMESTAMP" only for "TIMESTAMP" columns in MySQL --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index c70ff8d..bc55273 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -129,9 +129,9 @@ sub _extra_column_info { if ($info->{mysql_values}) { $extra_info{extra}{list} = $info->{mysql_values}; } -# XXX we need to distinguish between DEFAULT CURRENT_TIMESTAMP and DEFAULT 'foo' -# somehow, but DBI column_info doesn't preserve quotes. - if ($info->{COLUMN_DEF} =~ /^CURRENT_TIMESTAMP\z/i) { + if ( $info->{COLUMN_DEF} =~ /^CURRENT_TIMESTAMP\z/i + && $info->{mysql_type_name} =~ /^TIMESTAMP\z/i) { + $extra_info{default_value} = \'CURRENT_TIMESTAMP'; } diff --git a/t/11mysql_common.t b/t/11mysql_common.t index 151009f..0da0e39 100644 --- a/t/11mysql_common.t +++ b/t/11mysql_common.t @@ -32,8 +32,7 @@ my $tester = dbixcsl_common_tests->new( qq{ CREATE TABLE mysql_loader_test2 ( id INTEGER UNSIGNED NOT NULL PRIMARY KEY, - somedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - somestr VARCHAR(100) NOT NULL DEFAULT 'foo' + somets TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ) }, ], @@ -54,7 +53,7 @@ my $tester = dbixcsl_common_tests->new( 'MySQL ENUM values'); $rs = $schema->resultset($monikers->{mysql_loader_test2}); - $column_info = $rs->result_source->column_info('somedate'); + $column_info = $rs->result_source->column_info('somets'); my $default = $column_info->{default_value}; ok ((ref($default) eq 'SCALAR'), 'CURRENT_TIMESTAMP default_value is a scalar ref');