From: Ken Youens-Clark Date: Thu, 21 Aug 2003 18:10:14 +0000 (+0000) Subject: Now with check constraints! X-Git-Tag: v0.04~246 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8065e024b21b80e9926464012ed68c5ba3415cae;p=dbsrgits%2FSQL-Translator.git Now with check constraints! --- diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index ccb1fdb..400301b 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.14 2003-08-18 15:43:15 kycl4rk Exp $ +# $Id: PostgreSQL.pm,v 1.15 2003-08-21 18:10:14 kycl4rk Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , @@ -30,7 +30,7 @@ SQL::Translator::Producer::PostgreSQL - PostgreSQL producer for SQL::Translator use strict; use vars qw[ $DEBUG $WARN $VERSION ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/; $DEBUG = 1 unless defined $DEBUG; use SQL::Translator::Schema::Constants; @@ -347,7 +347,7 @@ sub produce { map { $_ =~ s/\(.+\)//; $_ } map { unreserve( $_, $table_name ) } $c->reference_fields; - next unless @fields; + next if !@fields && $c->type ne CHECK_C; if ( $c->type eq PRIMARY_KEY ) { $name ||= mk_name( $table_name, 'pk' ); @@ -365,6 +365,19 @@ sub produce { push @constraint_defs, "CONSTRAINT $name UNIQUE " . '("' . join( '", "', @fields ) . '")'; } + elsif ( $c->type eq CHECK_C ) { + my $s; + if ( $name ) { + $name ||= mk_name( + $table_name, $name || ++$c_name_default + ); + $name = next_unused_name($name, \%used_index_names); + $used_index_names{$name} = $name; + $s = 'CONSTRAINT $name '; + } + my $expression = $c->expression; + push @constraint_defs, "${s}CHECK ($expression)"; + } elsif ( $c->type eq FOREIGN_KEY ) { my $def = join(' ', map { $_ || () } 'FOREIGN KEY', $c->name