From: Allen Day Date: Mon, 2 Feb 2004 20:28:26 +0000 (+0000) Subject: merging patch from Dave Cash. description: X-Git-Tag: v0.06~224 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=37ce746e51a4ab1d515395841c7d241d6ef6a0cf;p=dbsrgits%2FSQL-Translator.git merging patch from Dave Cash. description: The new options are all boolean. If set to true, each does the following: show_datatypes display the datatype immediately after each field name show_sizes display the size of the field if the field is a CHAR, VARCHAR or VARCHAR2 field show_constraints display the primary key [PK], foreign key [FK] and unique [U] constraints on each field after the name (and optionally the datatype) of each field --- diff --git a/lib/SQL/Translator/Producer/GraphViz.pm b/lib/SQL/Translator/Producer/GraphViz.pm index 5044cda..8d15372 100644 --- a/lib/SQL/Translator/Producer/GraphViz.pm +++ b/lib/SQL/Translator/Producer/GraphViz.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::GraphViz; # ------------------------------------------------------------------- -# $Id: GraphViz.pm,v 1.8 2003-08-21 02:52:40 kycl4rk Exp $ +# $Id: GraphViz.pm,v 1.9 2004-02-02 20:28:26 allenday Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark # @@ -27,7 +27,7 @@ use SQL::Translator::Schema::Constants; use SQL::Translator::Utils qw(debug); use vars qw[ $VERSION $DEBUG ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use constant VALID_LAYOUT => { @@ -96,6 +96,9 @@ sub produce { my $add_color = $args->{'add_color'}; my $natural_join = $args->{'natural_join'}; my $show_fk_only = $args->{'show_fk_only'}; + my $show_datatypes = $args->{'show_datatypes'}; + my $show_sizes = $args->{'show_sizes'}; + my $show_constraints = $args->{'show_constraints'}; my $join_pk_only = $args->{'join_pk_only'}; my $skip_fields = $args->{'skip_fields'}; my %skip = map { s/^\s+|\s+$//g; $_, 1 } @@ -147,7 +150,26 @@ sub produce { @fields = grep { $_->is_foreign_key } @fields; } - my $field_str = join('\l', map { $_->name } @fields); + my $field_str = join( + '\l', + map { + '-\ ' + . $_->name + . ( $show_datatypes ? '\ ' . $_->data_type : '') + . ( $show_sizes && ! $show_datatypes ? '\ ' : '') + . ( $show_sizes && $_->data_type =~ /^(VARCHAR2?|CHAR)$/ ? '(' . $_->size . ')' : '') + . ( $show_constraints ? + ( $_->is_primary_key || $_->is_foreign_key || $_->is_unique ? '\ [' : '' ) + . ( $_->is_primary_key ? 'PK' : '' ) + . ( $_->is_primary_key && ($_->is_foreign_key || $_->is_unique) ? ',' : '' ) + . ( $_->is_foreign_key ? 'FK' : '' ) + . ( $_->is_unique && ($_->is_primary_key || $_->is_foreign_key) ? ',' : '' ) + . ( $_->is_unique ? 'U' : '' ) + . ( $_->is_primary_key || $_->is_foreign_key || $_->is_unique ? ']' : '' ) + : '' ) + . '\ ' + } @fields + ) . '\l'; my $label = $show_fields ? "{$table_name|$field_str}" : $table_name; $gv->add_node( $table_name, label => $label );