From: Rafael Kitover Date: Fri, 16 Apr 2010 21:56:00 +0000 (-0400) Subject: rewrite default_value 'now()' as 'CURRENT_TIMESTAMP' for Pg X-Git-Tag: 0.07000~63 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e64075f4ce173ab4cc2711450d78e358baf64a2;p=dbsrgits%2FDBIx-Class-Schema-Loader.git rewrite default_value 'now()' as 'CURRENT_TIMESTAMP' for Pg --- diff --git a/Changes b/Changes index f1ff591..e95d077 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - rewrite default_value \'now()' as \'CURRENT_TIMESTAMP' for Pg - use column_info instead of select to get Oracle column list (RT#42281) - match quotes in MySQL parser in more places (RT#42101) - fix unique detection in DB2 for multiple schemas (RT#39622) diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index 120256b..4ec2088 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -200,6 +200,11 @@ EOF $result->{$col}{sequence} = $1; delete $result->{$col}{default_value}; } + +# alias now() to current_timestamp for deploying to other DBs + if (eval { lc ${ $result->{$col}{default_value} } eq 'now()' }) { + $result->{$col}{default_value} = \'CURRENT_TIMESTAMP'; + } } return $result; diff --git a/t/12pg_common.t b/t/12pg_common.t index 723fc5a..f99ab9a 100644 --- a/t/12pg_common.t +++ b/t/12pg_common.t @@ -11,7 +11,6 @@ my $password = $ENV{DBICTEST_PG_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'Pg', auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY', - default_function => 'now()', dsn => $dsn, user => $user, password => $password, @@ -57,6 +56,8 @@ my $tester = dbixcsl_common_tests->new( 'time with time zone' => { data_type => 'time with time zone' }, 'time(2) with time zone' => { size => 2, data_type => 'time with time zone' }, timestamp => { data_type => 'timestamp without time zone' }, + 'timestamp default current_timestamp' + => { data_type => 'timestamp without time zone', default_value => \'CURRENT_TIMESTAMP' }, 'timestamp(2)' => { size => 2, data_type => 'timestamp without time zone' }, 'timestamp without time zone' => { data_type => 'timestamp without time zone' }, 'timestamp(2) without time zone' => { size => 2, data_type => 'timestamp without time zone' }, @@ -133,3 +134,4 @@ if( !$dsn || !$user ) { else { $tester->run_tests(); } +# vim:et sw=4 sts=4 tw=0: