From: Jess Robinson Date: Thu, 9 Nov 2006 18:16:24 +0000 (+0000) Subject: Add default timestamp support to Postgres producer X-Git-Tag: v0.11008~398 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f39e9c1215869bbc3598b5effb31f3d32e7ddee5;p=dbsrgits%2FSQL-Translator.git Add default timestamp support to Postgres producer --- diff --git a/Changes b/Changes index 26f5cd8..85cb72a 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,17 @@ # ----------------------------------------------------------- +# 0.08_03 +# ----------------------------------------------------------- + +* Added patch to use default values for Pg timestamp fields + +# ----------------------------------------------------------- +# 0.08_02 2006-11-03 +# ----------------------------------------------------------- + +* Added patch from Ash to separate DROP statements in mysql producer in list-context +* Fixed up SQLites usage of no-comments + +# ----------------------------------------------------------- # 0.08_01 2006-07-23 # ----------------------------------------------------------- diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 9ea1d69..c3e67b9 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::PostgreSQL; # ------------------------------------------------------------------- -# $Id: PostgreSQL.pm,v 1.25 2006-08-04 21:38:20 schiffbruechige Exp $ +# $Id: PostgreSQL.pm,v 1.26 2006-11-09 18:16:24 schiffbruechige Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -39,7 +39,7 @@ producer. use strict; use warnings; use vars qw[ $DEBUG $WARN $VERSION ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.25 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.26 $ =~ /(\d+)\.(\d+)/; $DEBUG = 1 unless defined $DEBUG; use SQL::Translator::Schema::Constants; @@ -430,13 +430,17 @@ sub create_table # # Default value -- disallow for timestamps # - my $default = $data_type =~ /(timestamp|date)/i - ? undef : $field->default_value; +# my $default = $data_type =~ /(timestamp|date)/i +# ? undef : $field->default_value; + my $default = $field->default_value; if ( defined $default ) { + my $qd = "'"; + $qd = '' if ($default eq 'now()' || + $default eq 'CURRENT_TIMESTAMP'); $field_def .= sprintf( ' DEFAULT %s', ( $field->is_auto_increment && $seq_name ) ? qq[nextval('"$seq_name"'::text)] : - ( $default =~ m/null/i ) ? 'NULL' : "'$default'" + ( $default =~ m/null/i ) ? 'NULL' : "$qd$default$qd" ); }