From: Rafael Kitover Date: Wed, 12 Aug 2009 00:58:06 +0000 (+0000) Subject: fix CURRENT_TIMESTAMP default for MySQL X-Git-Tag: 0.04999_08~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f430297e7b3d03fa6264972abe0f100f20102f80;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix CURRENT_TIMESTAMP default for MySQL --- diff --git a/Makefile.PL b/Makefile.PL index f061211..94329ba 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -9,6 +9,7 @@ test_requires 'DBI' => '1.56'; test_requires 'DBD::SQLite' => '1.12'; test_requires 'File::Path' => 0; test_requires 'IPC::Open3' => 0; +test_requires 'Test::Exception'; requires 'File::Spec' => 0; requires 'Scalar::Util' => 0; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index f2046b1..e101731 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -122,6 +122,7 @@ sub _table_uniq_info { } sub _extra_column_info { + no warnings 'uninitialized'; my ($self, $info) = @_; my %extra_info; @@ -134,6 +135,9 @@ sub _extra_column_info { if ($info->{mysql_values}) { $extra_info{extra}{list} = $info->{mysql_values}; } + if ($info->{COLUMN_DEF} =~ /^CURRENT_TIMESTAMP\z/i) { + $extra_info{default_value} = \'CURRENT_TIMESTAMP'; + } return \%extra_info; } diff --git a/t/11mysql_current_timestamp.t b/t/11mysql_current_timestamp.t new file mode 100644 index 0000000..8672f42 --- /dev/null +++ b/t/11mysql_current_timestamp.t @@ -0,0 +1,71 @@ +use strict; +use lib qw(t/lib); +use Test::More; +use DBI; + +my $DUMP_DIR; +BEGIN { + $DUMP_DIR = './t/_common_dump'; +} + +use lib $DUMP_DIR; +use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR"; +use File::Path; +use Test::Exception; + +my ($dsn, $user, $password) = map $ENV{"DBICTEST_MYSQL_$_"}, qw/DSN USER PASS/; + +if( !$dsn || !$user ) { + plan skip_all => 'You need to set the DBICTEST_MYSQL_DSN, _USER, and _PASS' + .' environment variables'; +} + +eval "use SQL::Translator '0.09007';"; +plan skip_all => 'SQL::Translator 0.09007 or greater required' + if $@; + +plan tests => 2; + +my $dbh = DBI->connect($dsn, $user, $password, { + RaiseError => 1, PrintError => 0 +}); + +eval { $dbh->do('DROP TABLE loadertest') }; +$dbh->do(q{ + CREATE TABLE loadertest ( + id INT PRIMARY KEY, + somedate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + somestr VARCHAR(100) NOT NULL DEFAULT 'foo' + ) Engine=InnoDB +}); +# XXX there needs to be code to distinguish these two types of defaults + +rmtree $DUMP_DIR; + +make_schema_at( + 'TestSL::Schema', + { + use_namespaces => 1, + constraint => qr/^loadertest\z/ + }, + [ $dsn, $user, $password, ] +); + +lives_ok { require TestSL::Schema } 'schema loads'; + +$dbh->do('DROP TABLE loadertest'); + +my $schema = TestSL::Schema->connect($dsn, $user, $password); + +my @warnings; +local $SIG{__WARN__} = sub { push @warnings, shift }; + +$schema->deploy; + +ok (not(grep /Invalid default/, @warnings)), 'default deployed'; +diag $_ for @warnings; + +END { + rmtree $DUMP_DIR; + eval { $dbh->do('DROP TABLE loadertest') }; +}